-
Notifications
You must be signed in to change notification settings - Fork 391
Open
Description
I am trying to implement an asymmetric validation middleware that uses RS256. In theory this should only need the public key to verify the JWT, but not including the private key does not work. I do not want to include the private key with the project. Below is my implementation.
`
authMiddleware, _ := app.New(&app.GinJWTMiddleware {
Realm: "zone",
SigningAlgorithm: "RS256",
PrivKeyFile: "keys/jwtRS256.key",
PubKeyFile: "keys/jwtRS256.key.pub",
PayloadFunc: func(data interface{}) app.MapClaims {
if v, ok := data.(*JWTToken); ok {
return app.MapClaims{
userName: v.UserName,
}
}
return app.MapClaims{}
},
IdentityHandler: func(c *gin.Context) interface{} {
claims := app.ExtractClaims(c)
return &JWTToken{
UserName: claims[userName].(string),
TokenType: claims[tokenType].(string),
}
},
Authorizator: func(data interface{}, c *gin.Context) bool {
if v, ok := data.(*JWTToken); ok && v.UserName == "admin" {
return true
}
return false
},
Unauthorized: func(c *gin.Context, code int, message string) {
c.JSON(code, gin.H{
"code": code,
"message": message,
})
},
TokenLookup: "header: Authorization, query: token, cookie: jwt",
TokenHeadName: "Bearer",
TimeFunc: time.Now,
})`
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels