Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( // AuthenticateHeader the Gin authenticate header AuthenticateHeader = "WWW-Authenticate" // AuthorizationHeader the auth header that gets passed to all services AuthorizationHeader = "Authorization" AuthorizationQuery = "Authorization" // HEADER used by the JWT middle ware HEADER = "header" QUERY = "query" // IssuerFieldName the issuer field name IssuerFieldName = "iss" )
Variables ¶
View Source
var AuthHeaderEmptyError = errors.New("HTTP authorization header empty")
View Source
var AuthQueryEmptyError = errors.New("HTTP authorization query empty")
Functions ¶
This section is empty.
Types ¶
type AuthMiddleware ¶
type AuthMiddleware struct { gin.Context, int, string) Timeout time.Duration // TokenLookup the header name of the token TokenLookup string // TimeFunc TimeFunc func() time.Time // Realm name to display to the user. Required. Realm string // to verify issuer VerifyIssuer bool // Region aws region Region string // UserPoolID the cognito user pool id UserPoolID string // The issuer Iss string // JWK public JSON Web Key (JWK) for your user pool JWK map[string]JWKKey // Allowed Client Ids AllowedClientIds []string }Unauthorized func(*
AuthMiddleware middleware
Example ¶
package main import ( jwt "github.com/Digital-Insight-Technologies-Ltd/gin-jwt-cognito" "github.com/gin-gonic/gin" ) func main() { // Creates a gin router with default middleware: router := gin.Default() // Create Cognito JWT auth middleware and set it in all authenticated endpoints mw, err := jwt.AuthJWTMiddleware("<some_iss>", "<some_userpool_id>", "region", []string{"clientid1", "clientid2"}, "header: "+jwt.AuthorizationHeader) if err != nil { panic(err) } router.GET("/someGet", mw.MiddlewareFunc(), func(context *gin.Context) { // some implementation }) router.POST("/somePost", mw.MiddlewareFunc(), func(context *gin.Context) { // some implementation }) router.PUT("/somePut", mw.MiddlewareFunc(), func(context *gin.Context) { // some implementation }) // By default, it serves on :8080 unless a // PORT environment variable was defined. err = router.Run() if err != nil { return } }
Output:
func AuthJWTMiddleware ¶
func AuthJWTMiddleware(iss, userPoolID, region string, allowedClientIds []string, tokenLookup string) (*AuthMiddleware, error)
AuthJWTMiddleware create an instance of the middle ware function
func (*AuthMiddleware) MiddlewareFunc ¶
func (mw *AuthMiddleware) MiddlewareFunc() gin.HandlerFunc
MiddlewareFunc implements the Middleware interface.
func (*AuthMiddleware) MiddlewareInit ¶
func (mw *AuthMiddleware) MiddlewareInit()
MiddlewareInit initialize jwt configs.
Click to show internal directories.
Click to hide internal directories.