Documentation
¶
Index ¶
- Constants
- Variables
- func CheckAuthorisation[T Authz](ctx context.Context, jwtSecret string, forResource string, permission int) (bool, error)
- func CreateToken[T Authz](cfg CreateTokenArgs, identity string, payload T) (string, time.Time, error)
- func GetClaims[T Authz](ctx context.Context, jwtSecret string) (T, error)
- func GetIdentity[T Authz](ctx context.Context, jwtSecret string) (string, error)
- func RefreshToken[T Authz](cfg CreateTokenArgs, oldToken string) (string, time.Time, error)
- func RefreshTokenWithGracePeriod[T Authz](cfg CreateTokenArgs, oldToken string, gracePeriod time.Duration) (string, bool, time.Time, error)
- type AuthClaims
- type Authz
- type CreateTokenArgs
Constants ¶
View Source
const ContextTokenKey = contextKey("jwtToken")
Variables ¶
View Source
var ( ErrNotAuthorized = errors.New("libauth: not authorized") ErrTokenExpired = errors.New("libauth: token has expired") ErrIssuedAtMissing = errors.New("libauth: issued at claim is missing") ErrIssuedAtInFuture = errors.New("libauth: token is malformed: issued-at time is in the future") ErrIdentityMissing = errors.New("libauth: identity claim is missing") ErrInvalidTokenClaims = errors.New("libauth: invalid token claims") ErrTokenMissing = errors.New("libauth: token is missing") ErrUnexpectedSigningMethod = errors.New("libauth: unexpected signing method") ErrTokenParsingFailed = errors.New("libauth: token parsing failed") ErrTokenSigningFailed = errors.New("libauth: token signing failed") ErrEmptyJWTSecret = errors.New("libauth: JWT secret cannot be empty") ErrEmptyIdentity = errors.New("libauth: identity cannot be empty") )
Functions ¶
func CheckAuthorisation ¶
func CreateToken ¶
func RefreshToken ¶
Types ¶
type AuthClaims ¶
type AuthClaims[T Authz] struct { jwt.RegisteredClaims Identity string `json:"identity"` Permissions T `json:"permissions"` }
func ValidateToken ¶
func (AuthClaims[T]) Valid ¶
func (c AuthClaims[T]) Valid() error
func (AuthClaims[T]) Validate ¶
func (c AuthClaims[T]) Validate() error
type CreateTokenArgs ¶
Click to show internal directories.
Click to hide internal directories.