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

Update how to handle jwtMiddleware in martini #78

Merged
merged 1 commit into from
Mar 12, 2021

Conversation

barismar
Copy link
Contributor

Description

FIx returning invalid response text/plain <invalid Value> instead of application/json { "text": "All good. You only get this message if you're authenticated"} when hit endpoint /secured/ping, how to fix this issue is by wrapping jwtMiddleware.CheckJWT with a function that requires params request and response that injected by Martini.

References

Include any links supporting this change such as a:

Testing

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not master

@barismar barismar changed the title Update how to handle jwtMiddleware Update how to handle jwtMiddleware in martini Feb 20, 2021
@@ -26,7 +26,9 @@ func StartServer() {
})

m.Get("/ping", PingHandler)
m.Get("/secured/ping", jwtMiddleware.CheckJWT, SecuredPingHandler)
m.Get("/secured/ping", func(w http.ResponseWriter, r *http.Request) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there! Thanks for submitting a PR.

I believe the root cause of this issue found in the paragraph right above the one linked in the pr https://github.com/go-martini/martini#return-values :

If a handler returns something, Martini will write the result to the current http.ResponseWriter as a string

The JWT Middleware we provide here will return an error or nil. When you wrap it like you did in this PR, the handler doesnt return anything and doesnt write to the response.

@grounded042 This might be something to think about as we rework the internals.

Aside from that, I think this is a fine workaround, albeit It is not ideal to have to use the middleware like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is definitely a bummer to have to use this workaround. Let's merge this in for now as it's great to have this, but in the future we should find a better way to handle this.

@grounded042 grounded042 merged commit 4c69730 into auth0:master Mar 12, 2021
barismar added a commit to barismar/go-jwt-middleware that referenced this pull request Mar 24, 2021
Update how to handle jwtMiddleware in Martini (auth0#78)
@barismar barismar deleted the fix/martini-example branch April 8, 2021 17:21
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

Successfully merging this pull request may close these issues.

None yet

3 participants