auth0

package
v2.0.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2018 License: MIT Imports: 7 Imported by: 3

Documentation

Index

Constants

View Source
const ContestRoles = "Roles"
View Source
const ContextUserID = "UserID"

Variables

This section is empty.

Functions

func ExtractClaims

func ExtractClaims(c *gin.Context) jwt.MapClaims

ExtractClaims help to extract the JWT claims

func ImpersonateFromHeader

func ImpersonateFromHeader() gin.HandlerFunc

ImpersonateFromHeader is a Gin Handler that sets userid based on the impersonate header.

Types

type GinAuth0Middleware

type GinAuth0Middleware struct {
	// Realm name to display to the user. Required.
	Realm string

	// signing algorithm - possible values are HS256, HS384, HS512
	// Optional, default is HS256.
	SigningAlgorithm string

	// Secret key used for signing. Required.
	Key interface{}

	// Duration that a jwt token is valid. Optional, defaults to one hour.
	Timeout time.Duration

	// This field allows clients to refresh their token until MaxRefresh has passed.
	// Note that clients can refresh their token in the last moment of MaxRefresh.
	// This means that the maximum validity timespan for a token is MaxRefresh + Timeout.
	// Optional, defaults to 0 meaning not refreshable.
	MaxRefresh time.Duration

	// Callback function that should perform the authorization of the authenticated user. Called
	// only after an authentication success. Must return true on success, false on failure.
	// Optional, default to success.
	Authorizator func(userID string, c *gin.Context) bool

	// Callback function that will be called during login.
	// Using this function it is possible to add additional payload data to the webtoken.
	// The data is then made available during requests via c.Get("JWT_PAYLOAD").
	// Note that the payload is not encrypted.
	// The attributes mentioned on jwt.io can't be used as keys for the map.
	// Optional, by default no additional data will be set.
	PayloadFunc func(userID string) map[string]interface{}

	// User can define own Unauthorized func.
	Unauthorized func(*gin.Context, int, string)

	// Set the identity handler function
	IdentityHandler func(jwt.MapClaims) string

	// 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 string

	// TokenHeadName is a string in the header. Default value is "Bearer"
	TokenHeadName string

	// TimeFunc provides the current time. You can override it to use another time value. This is useful for testing or if your server uses a different time zone than your tokens.
	TimeFunc func() time.Time

	//Audinece sets expected token audience
	Audience string

	//Issuer sets expected token issuer
	Issuer string
}

GinAuth0Middleware provides a Json-Web-Token authentication implementation for Auth0. On failure, a 401 HTTP response is returned. On success, the wrapped middleware is called, and the userID is made available as c.Get("userID").(string). The token then needs to be passed in the Authentication header. Example: Authorization:Bearer XXX_TOKEN_XXX

func (*GinAuth0Middleware) ExpectScope

func (mw *GinAuth0Middleware) ExpectScope(scope string) gin.HandlerFunc

ExpectScope is a Gin Handler that aborts connections missing the specified OAUTH scope.

func (*GinAuth0Middleware) MiddlewareFunc

func (mw *GinAuth0Middleware) MiddlewareFunc() gin.HandlerFunc

MiddlewareFunc makes GinAuth0Middleware implement the Middleware interface.

func (*GinAuth0Middleware) MiddlewareInit

func (mw *GinAuth0Middleware) MiddlewareInit() error

MiddlewareInit initialize jwt configs.

func (*GinAuth0Middleware) TokenGenerator

func (mw *GinAuth0Middleware) TokenGenerator(userID string) string

TokenGenerator handler that clients can use to get a jwt token.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL