Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // TokenHeadName is a string in the header. Default value is "Bearer" TokenHeadName = "Bearer" // APIKeyLookup is a string in the form of "<source>:<name>" that is used // to extract token from the request. // Optional. Default value "header:Authorization". // Possible values: // - "header:<name>" // - "query:<name>" // - "cookie:<name>" APIKeyLookup = "query:api_key,cookie:api_key,header:X-API-KEY" // TokenLookup is a string in the form of "<source>:<name>" that is used // to extract token from the request. // Optional. Default value "header:Authorization". // Possible values: // - "header:<name>" // - "query:<name>" // - "cookie:<name>" TokenLookup = "query:token,cookie:jwt,header:Authorization" // ErrNoClaims when HTTP status 403 is given ErrNoClaims = errors.New("invalid token") // ErrForbidden when HTTP status 403 is given ErrForbidden = errors.New("you don't have permission to access this resource") // ErrExpiredToken indicates JWT token has expired. Can't refresh. ErrExpiredToken = errors.New("token is expired") // ErrEmptyAuthHeader can be thrown if authing with a HTTP header, the Auth header needs to be set ErrEmptyAuthHeader = errors.New("auth header is empty") // ErrEmptyAPIKeyHeader can be thrown if authing with a HTTP header, the Auth header needs to be set ErrEmptyAPIKeyHeader = errors.New("api key header is empty") // ErrMissingExpField missing exp field in token ErrMissingExpField = errors.New("missing exp field") // ErrInvalidAuthHeader indicates auth header is invalid, could for example have the wrong Realm name ErrInvalidAuthHeader = errors.New("auth header is invalid") // ErrEmptyQueryToken can be thrown if authing with URL Query, the query token variable is empty ErrEmptyQueryToken = errors.New("query token is empty") // ErrEmptyCookieToken can be thrown if authing with a cookie, the token cokie is empty ErrEmptyCookieToken = errors.New("cookie token is empty") // ErrEmptyParamToken can be thrown if authing with parameter in path, the parameter in path is empty ErrEmptyParamToken = errors.New("parameter token is empty") // ErrInvalidSigningAlgorithm indicates signing algorithm is invalid, needs to be HS256, HS384, HS512, RS256, RS384 or RS512 ErrInvalidSigningAlgorithm = errors.New("invalid signing algorithm") //ErrRefreshTokenExpired tell the access token is invalid. Frontend should use refresh token to refresh access token. ErrInvalidAccessToken = errors.New("access token invalid") )
Functions ¶
func Middleware ¶
func Middleware(path string, cfg *utils.ServerConfig, db *mongodb.MongoDB) gin.HandlerFunc
Middleware wraps the request with auth middleware
func ParseAPIKey ¶
ParseAPIKey parse api key from gin context
func ParseToken ¶
func ParseToken(c *gin.Context, cfg *utils.ServerConfig) (t *jwt.Token, err error)
ParseToken parse jwt token from gin context,
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.