Documentation ¶
Index ¶
- Variables
- func CompareHash(data string, encodedHash string) (bool, error)
- func ComputeHash(data string) (*string, error)
- func GenerateOTP(length int) (*string, error)
- func GenerateRefreshCookie(value string) *fiber.Cookie
- func GenerateURLSafeToken(length int) (*string, error)
- func SetResponseTokens(c *fiber.Ctx, tokens *Token) *errors.Error
- func ValidatePassword(password string) *errors.Error
- type Claims
- type CustomClaims
- type JWTClient
- func (j *JWTClient) ExtractClaims(tokenString string, tokenType JWTType) (jwt.MapClaims, *errors.Error)
- func (j *JWTClient) GenerateToken(claims Claims, tokenType JWTType) ([]byte, *errors.Error)
- func (j *JWTClient) GenerateTokenPair(accessClaims, refreshClaims Claims) (*Token, *errors.Error)
- func (j *JWTClient) IsTokenValid(tokenString string, tokenType JWTType) (bool, *errors.Error)
- func (j *JWTClient) ParseToken(tokenString string, tokenType JWTType) (*jwt.Token, *errors.Error)
- func (j *JWTClient) RefreshToken(token, refreshToken string, tokenType JWTType, newClaims jwt.MapClaims) ([]byte, *errors.Error)
- type JWTClientInterface
- type JWTType
- type Permission
- type Token
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidHash = errors.New("the encoded hash is not in the correct format") ErrIncompatibleVersion = errors.New("incompatible version of argon2") )
Functions ¶
func ComputeHash ¶
func GenerateOTP ¶
func GenerateRefreshCookie ¶
func GenerateRefreshCookie(value string) *fiber.Cookie
func GenerateURLSafeToken ¶
func SetResponseTokens ¶
func ValidatePassword ¶
Types ¶
type CustomClaims ¶
type CustomClaims struct { jwt.StandardClaims Role string `json:"role"` }
func From ¶
func From(c *fiber.Ctx) (*CustomClaims, *errors.Error)
From extracts the CustomClaims from the fiber context Returns nil if the claims are not present
type JWTClient ¶
type JWTClient struct { RefreshExp time.Duration AccessExp time.Duration RefreshKey *m.Secret[string] AccessKey *m.Secret[string] SigningMethod jwt.SigningMethod }
func (*JWTClient) ExtractClaims ¶
func (j *JWTClient) ExtractClaims(tokenString string, tokenType JWTType) (jwt.MapClaims, *errors.Error)
ExtractClaims extracts the claims from the token. It returns the claims if successful, otherwise it returns an error.
func (*JWTClient) GenerateToken ¶
GenerateToken generates a token with the claims passed in. It returns the token if successful, otherwise it returns an error.
func (*JWTClient) GenerateTokenPair ¶
func (*JWTClient) IsTokenValid ¶
IsTokenValid checks if the token is valid. It returns true if the token is valid, otherwise it returns false.
func (*JWTClient) ParseToken ¶
ParseToken parses the token string and returns the token if successful, otherwise it returns an error. It uses the secret key for the token type to parse the token.
func (*JWTClient) RefreshToken ¶
func (j *JWTClient) RefreshToken(token, refreshToken string, tokenType JWTType, newClaims jwt.MapClaims) ([]byte, *errors.Error)
RefreshToken generates a new access token using the refresh token. It checks if the refresh token is valid and extracts the claims from the access token. It then updates the issued at and expires at claims and gives the new claims priority over the old claims. It returns the new access token if successful, otherwise it returns an error.
type JWTClientInterface ¶
type JWTClientInterface interface { GenerateTokenPair(accessClaims, refreshClaims Claims) (*Token, *errors.Error) GenerateToken(claims Claims, tokenType JWTType) ([]byte, *errors.Error) RefreshToken(token, refreshToken string, tokenType JWTType, newClaims jwt.MapClaims) ([]byte, *errors.Error) ExtractClaims(tokenString string, tokenType JWTType) (jwt.MapClaims, *errors.Error) ParseToken(tokenString string, tokenType JWTType) (*jwt.Token, *errors.Error) IsTokenValid(tokenString string, tokenType JWTType) (bool, *errors.Error) }
func NewJWTClient ¶
func NewJWTClient(authSettings config.AuthSettings, signingMethod jwt.SigningMethod) JWTClientInterface
type Permission ¶
type Permission string
const ( // User Management UserRead Permission = "user:read" UserWrite Permission = "user:write" UserDelete Permission = "user:delete" UserManageProfile Permission = "user:manage_profile" UserReadAll Permission = "user:read_all" // Tag Management TagRead Permission = "tag:read" TagCreate Permission = "tag:create" TagWrite Permission = "tag:write" TagDelete Permission = "tag:delete" // Club Management ClubRead Permission = "club:read" ClubCreate Permission = "club:create" ClubWrite Permission = "club:write" ClubDelete Permission = "club:delete" ClubManageMembers Permission = "club:manage_members" ClubManageFollowers Permission = "club:manage_followers" // Point of Contact Management PointOfContactRead Permission = "pointOfContact:read" PointOfContactCreate Permission = "pointOfContact:create" PointOfContactWrite Permission = "pointOfContact:write" PointOfContactDelete Permission = "pointOfContact:delete" // Comment Management CommentRead Permission = "comment:read" CommentCreate Permission = "comment:create" CommentWrite Permission = "comment:write" CommentDelete Permission = "comment:delete" // Event Management EventRead Permission = "event:read" EventCreate Permission = "event:create" EventWrite Permission = "event:write" EventDelete Permission = "event:delete" EventManageRSVPs Permission = "event:manage_rsvps" // Contact Management ContactRead Permission = "contact:read" ContactCreate Permission = "contact:create" ContactWrite Permission = "contact:write" ContactDelete Permission = "contact:delete" // Category Management CategoryRead Permission = "category:read" CategoryCreate Permission = "category:create" CategoryWrite Permission = "category:write" CategoryDelete Permission = "category:delete" // Notification Management NotificationRead Permission = "notification:read" NotificationCreate Permission = "notification:create" NotificationWrite Permission = "notification:write" NotificationDelete Permission = "notification:delete" // Global Permissions (for convenience) ReadAll Permission = "all:read" CreateAll Permission = "all:create" WriteAll Permission = "all:write" DeleteAll Permission = "all:delete" )
func GetPermissions ¶
func GetPermissions(role models.UserRole) []Permission