authenticationhandler

package
v0.1.53 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2024 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

authenticationhandler/tokenmanager.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidClientID

func IsValidClientID(clientID string) (bool, string)

IsValidClientID checks if the provided client ID is a valid UUID. Returns true if valid, along with an empty error message; otherwise, returns false with an error message.

func IsValidClientSecret

func IsValidClientSecret(clientSecret string) (bool, string)

IsValidClientSecret checks if the provided client secret meets your application's validation criteria. Returns true if valid, along with an empty error message; otherwise, returns false with an error message.

func IsValidPassword

func IsValidPassword(password string) (bool, string)

IsValidPassword checks if the provided password meets your application's validation criteria. Returns true if valid, along with an empty error message; otherwise, returns false with an error message.

func IsValidUsername

func IsValidUsername(username string) (bool, string)

IsValidUsername checks if the provided username meets password safe validation criteria. Returns true if valid, along with an empty error message; otherwise, returns false with an error message.

Types

type AuthTokenHandler

type AuthTokenHandler struct {
	Credentials  ClientCredentials // Credentials holds the authentication credentials.
	Token        string            // Token holds the current authentication token.
	Expires      time.Time         // Expires indicates the expiry time of the current authentication token.
	Logger       logger.Logger     // Logger provides structured logging capabilities for logging information, warnings, and errors.
	AuthMethod   string            // AuthMethod specifies the method of authentication, e.g., "bearer" or "oauth".
	InstanceName string            // InstanceName represents the name of the instance or environment the client is interacting with.

	HideSensitiveData bool
	// contains filtered or unexported fields
}

AuthTokenHandler manages authentication tokens.

func NewAuthTokenHandler

func NewAuthTokenHandler(logger logger.Logger, authMethod string, credentials ClientCredentials, instanceName string, hideSensitiveData bool) *AuthTokenHandler

NewAuthTokenHandler creates a new instance of AuthTokenHandler.

func (*AuthTokenHandler) BasicAuthTokenAcquisition added in v0.1.37

func (h *AuthTokenHandler) BasicAuthTokenAcquisition(apiHandler apihandler.APIHandler, httpClient *http.Client, username string, password string) error

BasicAuthTokenAcquisition fetches and sets an authentication token using the stored basic authentication credentials.

func (*AuthTokenHandler) CheckAndRefreshAuthToken added in v0.1.37

func (h *AuthTokenHandler) CheckAndRefreshAuthToken(apiHandler apihandler.APIHandler, httpClient *http.Client, clientCredentials ClientCredentials, tokenRefreshBufferPeriod time.Duration) (bool, error)

CheckAndRefreshAuthToken checks the token's validity and refreshes it if necessary. It returns true if the token is valid post any required operations and false with an error otherwise.

func (*AuthTokenHandler) OAuth2TokenAcquisition added in v0.1.37

func (h *AuthTokenHandler) OAuth2TokenAcquisition(apiHandler apihandler.APIHandler, httpClient *http.Client, clientID, clientSecret string) error

OAuth2TokenAcquisition fetches an OAuth access token using the provided client ID and client secret. It updates the AuthTokenHandler's Token and Expires fields with the obtained values.

func (*AuthTokenHandler) RefreshBearerToken added in v0.1.37

func (h *AuthTokenHandler) RefreshBearerToken(apiHandler apihandler.APIHandler, httpClient *http.Client) error

RefreshBearerToken refreshes the current authentication token.

type ClientCredentials

type ClientCredentials struct {
	Username     string
	Password     string
	ClientID     string
	ClientSecret string
}

ClientCredentials holds the credentials necessary for authentication.

type OAuthResponse

type OAuthResponse struct {
	AccessToken  string `json:"access_token"`            // AccessToken is the token that can be used in subsequent requests for authentication.
	ExpiresIn    int64  `json:"expires_in"`              // ExpiresIn specifies the duration in seconds after which the access token expires.
	TokenType    string `json:"token_type"`              // TokenType indicates the type of token, typically "Bearer".
	RefreshToken string `json:"refresh_token,omitempty"` // RefreshToken is used to obtain a new access token when the current one expires.
	Error        string `json:"error,omitempty"`         // Error contains details if an error occurs during the token acquisition process.
}

OAuthResponse represents the response structure when obtaining an OAuth access token.

type TokenResponse

type TokenResponse struct {
	Token   string    `json:"token"`
	Expires time.Time `json:"expires"`
}

TokenResponse represents the structure of a token response from the API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL