Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assymmetric key validation should have to use private key file #236

Open
JamesPiggott opened this issue Mar 6, 2020 · 2 comments
Open

Comments

@JamesPiggott
Copy link

JamesPiggott commented Mar 6, 2020

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,
})`
@aesadde
Copy link

aesadde commented Apr 15, 2020

@JamesPiggott I've been trying to do the same. No need to use private key if the service only needs to extract claims and validate the token.

For now I've resorted to my own solution but it would be nice to have the option here as well.

@DanielKrolopp
Copy link

I have the same issue. I've found that including a dummy private key works---as long as it is a valid key (ie: all '0's doesn't work). I just generated a random one from here: https://travistidwell.com/jsencrypt/demo/ and included it with my project as a placeholder until this bug is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants