Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrTokenExpired = errors.New("token expired") ErrInvalidAccessToken = errors.New("invalid access token") ErrInvalidRefreshToken = errors.New("invalid refresh token") )
The list of jwt token errors presented to the end user.
Functions ¶
func AuthenticateRefreshJWT ¶
AuthenticateRefreshJWT checks validity of refresh tokens and is only used for access token refresh and logout requests. It responds with 401 Unauthorized for invalid or expired refresh tokens.
func Authenticator ¶
Authenticator is a default authentication middleware to enforce access from the Verifier middleware request context values. The Authenticator sends a 401 Unauthorized response for any unverified tokens and passes the good ones through.
func ErrUnauthorized ¶
ErrUnauthorized renders status 401 Unauthorized with custom error message.
func RefreshTokenFromCtx ¶
RefreshTokenFromCtx retrieves the parsed refresh token from context.
Types ¶
type AppClaims ¶
AppClaims represent the claims parsed from JWT access token.
func ClaimsFromCtx ¶
ClaimsFromCtx retrieves the parsed AppClaims from request context.
type ErrResponse ¶
type ErrResponse struct { Err error `json:"-"` // low-level runtime error HTTPStatusCode int `json:"-"` // http response status code StatusText string `json:"status"` // user-level status message AppCode int64 `json:"code,omitempty"` // application-specific error code ErrorText string `json:"error,omitempty"` // application-level error message, for debugging }
ErrResponse renderer type for handling all sorts of errors.
func (*ErrResponse) Render ¶
func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error
Render sets the application-specific error code in AppCode.
type RefreshClaims ¶
type RefreshClaims struct {
Token string
}
RefreshClaims represent the claims parsed from JWT refresh token.
func (*RefreshClaims) ParseClaims ¶
func (c *RefreshClaims) ParseClaims(claims jwtauth.Claims) error
ParseClaims parses the JWT claims into RefreshClaims.
type Token ¶
type Token struct { ID int `json:"id,omitempty"` CreatedAt time.Time `json:"created_at,omitempty"` UpdatedAt time.Time `json:"updated_at,omitempty"` AccountID int `json:"-"` Token string `json:"-"` Expiry time.Time `json:"-"` Mobile bool `sql:",notnull" json:"mobile"` Identifier string `json:"identifier,omitempty"` }
Token holds refresh jwt information.
func (*Token) BeforeInsert ¶
BeforeInsert hook executed before database insert operation.
func (*Token) BeforeUpdate ¶
BeforeUpdate hook executed before database update operation.
type TokenAuth ¶
type TokenAuth struct { JwtAuth *jwtauth.JWTAuth JwtExpiry time.Duration JwtRefreshExpiry time.Duration }
TokenAuth implements JWT authentication flow.
func NewTokenAuth ¶
NewTokenAuth configures and returns a JWT authentication instance.
func (*TokenAuth) CreateRefreshJWT ¶
CreateRefreshJWT returns a refresh token for provided token Claims.
func (*TokenAuth) GenTokenPair ¶
GenTokenPair returns both an access token and a refresh token.