Documentation ¶
Index ¶
- Constants
- Variables
- type Authenticator
- type Claims
- type Client
- func (c *Client) GenerateAnonymousTokens(userID string, flow FlowType) (*Tokens, error)
- func (c *Client) GenerateUserTokens(username, password string, flow FlowType) (*Tokens, error)
- func (c *Client) JWTKey() *rsa.PrivateKey
- func (c *Client) Refresh(refreshToken string) (*Tokens, error)
- func (c *Client) Revoke(accessToken string) error
- func (c *Client) ValidateAccessToken(accessToken string) (*Claims, error)
- type FlowType
- type Level
- type Repository
- type Tokens
- type User
- type UserServiceClient
Constants ¶
const ( AccessTokenExpiration string = "accessTokenExpiration" AnonymousExpiration string = "anonymousExpiration" ShortRefreshTokenExpiration string = "shortRefreshTokenExpiration" LongRefreshTokenExpiration string = "longRefreshTokenExpiration" )
Expiration map valid keys.
Variables ¶
var ( ErrInternalError = errors.New("internal error") )
Common errors.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator interface { // GenerateAnonymousTokens generate authentication tokens for anonymous user. GenerateAnonymousTokens(userID string, flow FlowType) (*Tokens, error) // GenerateUserTokens generate authentication tokens for logged-in user. GenerateUserTokens(username, password string, flow FlowType) (*Tokens, error) // Revoke revokes an access token registered for a given refresh token. Revoke(accessToken string) error // Refresh refreshes an user authentication tokens. Refresh(refreshToken string) (*Tokens, error) // ValidateAccessToken checks if logged-in user authentication token exists. ValidateAccessToken(accessToken string) (*Claims, error) // JWTKey returns the authenticator JWT Keys. JWTKey() *rsa.PrivateKey }
Authenticator is the interface for the authentication methods.
type Claims ¶
type Claims struct { Name string `json:"name,omitempty"` Level Level `json:"level"` jwt.RegisteredClaims }
Claims represents JWT claims data structure.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements the Authenticator interface.
func NewClient ¶
func NewClient( logger *log.Logger, userServiceClient UserServiceClient, refreshTokenRepository, accessTokenRepository, flowRepository Repository, issuer string, expiration map[string]time.Duration, jwtKey *rsa.PrivateKey, ) *Client
NewClient returns a new instance of authentication Client.
func (*Client) GenerateAnonymousTokens ¶
GenerateAnonymousTokens generate authentication tokens for anonymous user.
func (*Client) GenerateUserTokens ¶
GenerateUserTokens generate authentication tokens for logged-in user.
func (*Client) JWTKey ¶
func (c *Client) JWTKey() *rsa.PrivateKey
type Repository ¶
type Repository interface { // Keys retrieves keys matching the specified pattern. Keys(ctx context.Context, pattern string) ([]string, error) // Get retrieves the value associated with the specified key. Get(ctx context.Context, key string) (string, error) // Set sets the value associated with the specified key with an optional expiration duration. Set(ctx context.Context, key, value string, expiration time.Duration) error // Del deletes the value associated with the specified key. Del(ctx context.Context, key string) error }
Repository is the interface for the authenticator storage repository.
type Tokens ¶
type Tokens struct { RefreshToken string `json:"refreshToken,omitempty"` AccessToken string `json:"accessToken"` AccessTokenExpiration int64 `json:"accessTokenExpiration"` RefreshTokenExpiration int64 `json:"refreshTokenExpiration,omitempty"` }
Tokens represents the authentication token json response.
type User ¶
type User struct { Username string `json:"username"` Name string `json:"name"` Level Level `json:"level"` }
User represents a user entity.
type UserServiceClient ¶
type UserServiceClient interface { // CheckCredentials checks the credentials of a user. CheckCredentials(username, md5Password string) (*User, error) }
UserServiceClient is an interface for interacting with the user service.
func NewUserServiceClient ¶
func NewUserServiceClient(timeout time.Duration, endpoint string, logger *log.Logger) UserServiceClient
NewUserServiceClient creates a new instance of the user service client.