Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTokenExpired = errors.New("token expired")
ErrTokenExpired is an error that is returned when a JWT token is expired.
Functions ¶
This section is empty.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
NewManager creates a new Manager instance with the given secret key.
The secret key is expected to be a non-empty string. If the secret key is empty, an error is returned.
func (*Manager) GenerateToken ¶
GenerateToken generates a new JWT token for the given user ID and audience.
The token is valid for 12 hours from the time it is generated. The subject claim is set to the given user ID. The audience claim is set to the given audience. The token is signed with the secret key set on the Manager during initialization.
If the token cannot be generated, an error is returned.
func (*Manager) ValidateToken ¶
ValidateToken validates a JWT token and returns the user ID string if the validation is successful. If the token is invalid or expired, an error is returned. The error is wrapped with jwt.ErrTokenExpired if the token is expired. The error is wrapped with jwt.ErrTokenExpired if the token is expired.