authenticationhandler

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

authenticationhandler/auth_token_management.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) ObtainOAuthToken

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

ObtainOAuthToken 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) ObtainToken

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

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

func (*AuthTokenHandler) RefreshToken

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

RefreshToken refreshes the current authentication token.

func (*AuthTokenHandler) ValidAuthTokenCheck

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

ValidAuthTokenCheck checks if the current token is valid and not close to expiry. If the token is invalid, it tries to refresh it. It returns a boolean indicating the validity of the token and an error if there's a failure.

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