Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( DefaultAccessTokenExpires = time.Hour * 2 DefaultRefreshTokenExpires = time.Hour * 24 * 30 DefaultSigningMethod = jwt.SigningMethodHS256 )
Functions ¶
This section is empty.
Types ¶
type Claims ¶
type Claims struct { // The identity of this token, which can be any data that is json serializable. Identity interface{} // Every time a user authenticates by providing a username and password, // they receive a Fresh access token that can access any route. // // But after some time, that token should no longer be considered fresh, // and some critical or dangerous routes will be blocked until the user verifies their password again. Fresh bool // TokenType includes AccessTokenType and RefreshTokenType. TokenType TokenType jwt.RegisteredClaims }
Claims is the custom claims type.
func (*Claims) GetIdentity ¶ added in v0.8.1
func (c *Claims) GetIdentity() interface{}
func (*Claims) HasExpired ¶
HasExpired returns true if the token has expired.
type JwtAuth ¶
type JwtAuth struct {
*Options
}
func New ¶
New returns new JwtAuth.
The SecretKey is used to sign the token.
The default options are:
- AccessTokenExpires: DefaultAccessTokenExpires
- RefreshTokenExpires: DefaultRefreshTokenExpires
- SigningMethod: DefaultSigningMethod
func (*JwtAuth) CreateAccessToken ¶
CreateAccessToken create a new access token. The identity of this token, which can be any data that is json serializable.
func (*JwtAuth) CreateRefreshToken ¶
CreateRefreshToken create a new refresh token. The identity of this token, which can be any data that is json serializable.
func (*JwtAuth) ParseJwtToken ¶
type Option ¶
type Option func(*Options)
func WithAccessTokenExpires ¶
WithAccessTokenExpires sets the expiration time of the access token.
func WithAudience ¶
WithAudience sets the audience of the token.
func WithRefreshTokenExpires ¶
WithRefreshTokenExpires sets the expiration time of the refresh token.
func WithSubject ¶
WithSubject sets the subject of the token.
type Options ¶
type Options struct { // SecretKey is the secret key used to sign the token. // It is required. SecretKey string // Issuer is the issuer of the token. Issuer string // Subject is the subject of the token. Subject string // Audience is the audience of the token. Audience []string // AccessTokenExpires is the expiration time of the access token. AccessTokenExpires time.Duration // RefreshTokenExpires is the expiration time of the refresh token. RefreshTokenExpires time.Duration }
Options is a struct for specifying configuration options for the JWT.