Documentation
¶
Index ¶
- Constants
- Variables
- func HasAllPermissions(principal *bebo.Principal, permissions ...string) bool
- func HasAllRoles(principal *bebo.Principal, roles ...string) bool
- func HasAnyPermission(principal *bebo.Principal, permissions ...string) bool
- func HasAnyRole(principal *bebo.Principal, roles ...string) bool
- func HasPermission(principal *bebo.Principal, permission string) bool
- func HasRole(principal *bebo.Principal, role string) bool
- func SignHS256(key JWTKey, claims map[string]any) (string, error)
- type JWTAuthenticator
- type JWTKey
- type JWTKeySet
- type PermissionAuthorizer
- type RoleAuthorizer
Constants ¶
const PermissionClaim = "permissions"
PermissionClaim is the JWT claim used for permissions.
Variables ¶
var ( // ErrInvalidToken indicates a malformed or invalid token. ErrInvalidToken = errors.New("invalid token") // ErrUnsupportedAlg indicates an unsupported signing algorithm. ErrUnsupportedAlg = errors.New("unsupported jwt alg") // ErrExpiredToken indicates an expired token. ErrExpiredToken = errors.New("token expired") // ErrNotBefore indicates a token that is not valid yet. ErrNotBefore = errors.New("token not valid yet") // ErrInvalidIssuer indicates an issuer mismatch. ErrInvalidIssuer = errors.New("token issuer invalid") // ErrInvalidAudience indicates an audience mismatch. ErrInvalidAudience = errors.New("token audience invalid") )
var ( // ErrMissingRole indicates a missing required role. ErrMissingRole = errors.New("missing required role") // ErrMissingPermission indicates a missing required permission. ErrMissingPermission = errors.New("missing required permission") )
var ErrInvalidKey = errors.New("invalid signing key")
ErrInvalidKey indicates a missing signing key.
Functions ¶
func HasAllPermissions ¶
HasAllPermissions reports whether a principal has all of the provided permissions.
func HasAllRoles ¶
HasAllRoles reports whether a principal has all of the provided roles.
func HasAnyPermission ¶
HasAnyPermission reports whether a principal has any of the provided permissions.
func HasAnyRole ¶
HasAnyRole reports whether a principal has any of the provided roles.
func HasPermission ¶
HasPermission reports whether a principal has the given permission.
Types ¶
type JWTAuthenticator ¶
type JWTAuthenticator struct {
Key []byte
Keys [][]byte
KeySet *JWTKeySet
Issuer string
Audience string
Header string
Scheme string
ClockSkew time.Duration
Now func() time.Time
}
JWTAuthenticator validates HS256 JWT tokens.
func (JWTAuthenticator) Authenticate ¶
Authenticate validates a JWT bearer token from the request.
type JWTKeySet ¶
JWTKeySet supports signing and verifying with rotating keys.
type PermissionAuthorizer ¶
PermissionAuthorizer requires permissions for authorization.
func RequireAnyPermission ¶
func RequireAnyPermission(permissions ...string) PermissionAuthorizer
RequireAnyPermission enforces at least one permission.
func RequirePermissions ¶
func RequirePermissions(permissions ...string) PermissionAuthorizer
RequirePermissions enforces all permissions.
type RoleAuthorizer ¶
RoleAuthorizer requires roles for authorization.
func RequireAnyRole ¶
func RequireAnyRole(roles ...string) RoleAuthorizer
RequireAnyRole enforces at least one role.
func RequireRoles ¶
func RequireRoles(roles ...string) RoleAuthorizer
RequireRoles enforces all roles.