Documentation ¶
Index ¶
- Constants
- func AuthLevelVerifierFactory(minLevel common.AuthLevel, jwtProvider JWTProvider, jwtSecret []byte, ...) gin.HandlerFunc
- func CompareHashAndPassword(hash, password string) error
- func GetHashForPassword(password string) (string, error)
- func NewJWT(user entities.User, timestamp int64, validityDuration int64, ...) (string, error)
- type Claims
- type JWTProvider
- type TokenType
Constants ¶
const AuthTokenKeyInCtx = "Authorization"
AuthTokenKeyInCtx is the key where the auth token is stored inside a request's context
Variables ¶
This section is empty.
Functions ¶
func AuthLevelVerifierFactory ¶
func AuthLevelVerifierFactory(minLevel common.AuthLevel, jwtProvider JWTProvider, jwtSecret []byte, failCallback gin.HandlerFunc) gin.HandlerFunc
AuthLevelVerifierFactory creates a middleware that checks if the request contains a valid JWT provided by the jwtProvider and confirms that the requester has an auth level which is greater than or equal to minLevel. Auth claims get stored in "Authorization" if token is valid calls failCallback otherwise
func CompareHashAndPassword ¶
CompareHashAndPassword compares the hash to the password. If they both represent the same string, returns nill. Returns an error otherwise
func GetHashForPassword ¶
GetHashForPassword generates a hash for the given password with the given salt
Types ¶
type Claims ¶
type Claims struct { jwt.StandardClaims AuthLevel common.AuthLevel `json:"auth_level"` TokenType TokenType `json:"token_type"` }
Claims is the model for the claims in the JWT token
func ExtractClaimsFromCtx ¶
ExtractClaimsFromCtx extracts auth claims from a request context. Returns nil if they do not exist or cannot be decoded
func GetJWTClaims ¶
GetJWTClaims checks if the given token is a valid JWT with given secret and returns the claims inside the token. Returns nill if the token is invalid
type JWTProvider ¶
JWTProvider is a wrapper type for a function which returns a JWT from a request's context