Documentation ¶
Overview ¶
Package userclaimjwt provides a auto-generated package which contains a API for authentication using JWT.
Index ¶
- Variables
- type Identities
- type Identity
- type IdentityAccess
- type IdentityBackend
- type IdentityDB
- type IdentityInfo
- type IdentityMaker
- type IdentityOps
- type IdentityToken
- type JWTAuth
- type JWTClaim
- type JWTConfig
- type JWTError
- type JWTIdentity
- func (jwa JWTIdentity) Authenticate(ctx context.Context, accessToken string) (example.UserClaim, error)
- func (jwa JWTIdentity) Grant(ctx context.Context, cr example.CreateUserSession) (JWTAuth, error)
- func (jwa JWTIdentity) Refresh(ctx context.Context, encodedRefreshToken string) (JWTAuth, error)
- func (jwa JWTIdentity) Revoke(ctx context.Context, encodedRefreshToken string) error
- type Testimony
- type TokenSecrets
- type TokenValidator
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrInvalidIdentity = errors.New("provided Identity is invalid") ErrParseJWTToken = errors.New("parse error: invalid jwt token") ErrNoJWTAuthorizationToken = errors.New("no jwt authorization token") ErrInternalError = errors.New("backend failed with error") ErrInvalidJWTToken = errors.New("received jwt token is invalid") ErrUnexpectedJWTClaim = errors.New("jwt token claim is not expected type") ErrExpiredJWTToken = errors.New("received jwt token is expired") ErrInvalidRefreshToken = errors.New("Invalid refresh token") ErrTokenRefreshDenied = errors.New("refresh_token already blacklist") ErrExpiredRefreshToken = errors.New("refresh_token already expired") ErrNoTargetHeaderInToken = errors.New("token.Header has no 'jwt-target-id'") ErrExpiredAccessToken = errors.New("access_token already expired") ErrInvalidSigningMethod = errors.New("token signing method mismatched") ErrFailedToGetSecret = errors.New("target-id failed to get secret from secrets function") )
errors ...
Functions ¶
This section is empty.
Types ¶
type Identities ¶
type Identities struct { Page int `json:"page"` ResponsePerPage int `json:"responsePerPage"` TotalRecords int `json:"total_records"` Records []Identity `json:"records"` }
Identities defines a type to represent the response given to a request for all records of the type example.Identity.
type Identity ¶
type Identity struct { PublicID string `json:"public_id"` RefreshToken string `json:"refresh_token"` Expires int64 `json:"expires"` TargetID string `json:"target_id"` LastLogin int64 `json:"last_login"` IssuedAt int64 `json:"last_login"` RefreshInterval time.Duration `json:"refresh_interval"` Data example.UserClaim `json:"data"` }
Identity embodies data stored for a user's login credentials.
type IdentityAccess ¶
IdentityAccess embodies data received over api calls to revoke or refresh a identity token.
type IdentityBackend ¶
type IdentityBackend interface { IdentityOps Count(context.Context) (int, error) Delete(context.Context, string) error Get(context.Context, string) (Identity, error) Update(context.Context, string, Identity) error GetAll(context.Context, string, string, int, int) ([]Identity, int, error) }
IdentityBackend defines an interface that expose a backend interface which can expose methods that contain all necessary logic for interaction with api for http endpoints.
type IdentityDB ¶
type IdentityDB interface { Count(ctx context.Context) (int, error) Delete(ctx context.Context, publicID string) error Create(ctx context.Context, elem Identity) error Get(ctx context.Context, publicID string) (Identity, error) Update(ctx context.Context, publicID string, elem Identity) error GetAllByOrder(ctx context.Context, order string, orderBy string) ([]Identity, error) GetByField(ctx context.Context, key string, value interface{}) (Identity, error) GetAll(ctx context.Context, order string, orderBy string, page int, responsePerPage int) ([]Identity, int, error) }
IdentityDB defines an interface which exposes a underline storage system for retrieving and storing identity records. @implement
type IdentityInfo ¶
type IdentityInfo struct {
Total int `json:"total"`
}
IdentityInfo contains meta-data regarding all records in db of type Identity.
type IdentityMaker ¶
IdentityMaker defines a function type provided by maker for generating identity claim.
type IdentityOps ¶
type IdentityOps interface { Revoke(context.Context, string) error Refresh(context.Context, string) (JWTAuth, error) Grant(context.Context, example.CreateUserSession) (JWTAuth, error) Authenticate(context.Context, string) (example.UserClaim, error) }
IdentityOps embodies method specific for grant, authenticating, revoking and refreshing identities.
type IdentityToken ¶
type IdentityToken struct {
RefreshToken string `json:"refresh_token"`
}
IdentityToken embodies data received over api calls to refresh or revoke a identity token.
type JWTAuth ¶
type JWTAuth struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` TokenType string `json:"token_type"` Expires int64 `json:"expires"` RefreshExpires int64 `json:"refresh_expires"` }
JWTAuth embodies data provided as response to a token refresh or sso login operation.
type JWTClaim ¶
type JWTClaim struct { jwt.StandardClaims SpecialID string `json:"special_id"` Data example.UserClaim }
JWTClaim embodies the data attached with the standard claims.
type JWTConfig ¶
type JWTConfig struct { Signer string AccessTokenExpires time.Duration RefreshTokenExpires time.Duration Maker IdentityMaker Secrets TokenSecrets Validator TokenValidator Method jwt.SigningMethod }
JWTConfig embodies the field for configuring JWTBackend.
type JWTIdentity ¶
type JWTIdentity struct { IdentityDB // contains filtered or unexported fields }
JWTIdentity implements the IdentityBackend interface and embodies all necessary method for granting, revoking and refreshing jwt access and refresh tokens.
func NewJWTIdentity ¶
func NewJWTIdentity(config JWTConfig, whitelist tokens.TokenSet, blacklist tokens.TokenSet, backend IdentityDB) JWTIdentity
NewJWTIdentity returns a new JWTIdentity instance which embodies and implements the IdentityBackend interface.
func (JWTIdentity) Authenticate ¶
func (jwa JWTIdentity) Authenticate(ctx context.Context, accessToken string) (example.UserClaim, error)
Authenticate attempts to authenticate users access token to validate user's
func (JWTIdentity) Grant ¶
func (jwa JWTIdentity) Grant(ctx context.Context, cr example.CreateUserSession) (JWTAuth, error)
Grant generates a new jwt token for provided credential contract if valiated to be correct and authorizable. It returns a json of JWTClaim.
type TokenSecrets ¶
TokenSecrets defines a function type when provided the config and target id received from the Identity maker will return a byte slice which represent the secret the token is signed with.