Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RoleHierarchy = map[string][]string{
"admin": {"read", "write", "admin"},
"write": {"read", "write"},
"read": {"read"},
}
RoleHierarchy defines the relationship between roles and their associated scopes. Each role is mapped to a list of permissible scopes. This hierarchy is used to determine whether a user with a given role has access to specific actions.
Example:
- "admin" includes "read", "write", and "admin" scopes.
- "write" includes "read" and "write" scopes.
- "read" includes only the "read" scope.
Functions ¶
func GenerateAllowedRoles ¶
GenerateAllowedRoles extracts the keys from RoleHierarchy to create a list of allowed roles.
Types ¶
type CustomClaims ¶
type CustomClaims struct { Roles []string `json:"roles" validate:"required,dive,oneof=read write admin"` jwt.RegisteredClaims }
CustomClaims defines the structure of your token claims
type Manager ¶
type Manager interface { // Generate generates a signed JWT with the given roles. Generate( signingKey string, roles []string, subject string, ) (string, error) // Validate parses and validates the JWT. Validate( tokenString string, signingKey string, ) (*CustomClaims, error) }
Manager responsible for Token operations.
Click to show internal directories.
Click to hide internal directories.