-
Notifications
You must be signed in to change notification settings - Fork 177
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
Add JWT authentication #91
Comments
I'm trying to implement JWT auth using this beautiful starter project, but got into troubles. Whenever i need to protect all endpoints, go-kit provided middleware working just fine.
But how do i protect only few endpoints? For example users service where registration / login should not be protected by jwt auth. If i skip jwt token i'm getting pretty non informative response and log message
Could you please suggest better way of implementing jwt ? |
You need two sets of The 500 error is because JWT errors are returned in the endpoint layer and the generic ErrorEncoder doesn't know how to handle does, so it falls back to 500 error. Personally I think this is the biggest flaw in go-kit at the moment. I explained this issue in details here: go-kit/kit#923 I don't have an immediate answer to this issue. The best you can do at the moment is writing your own error encoder that knows these error types: https://github.com/go-kit/kit/blob/492a87e/auth/jwt/middleware.go#L24-L45 That way you can return 401 properly. I plan come up with a solution, I have a few ideas actually, but none of them make me perfectly happy. |
That means all errors you are returning in endpoints will result as the same generic ErrorEncoder message. Example:
I tested my endpoints that i made same as yours and can confirm that. |
That's correct. Sometimes you want that (eg. there are no business errors returned from your service), but that's not always the case. |
Keep the current TODO API for simplicity? Or create a new API with protected resources?
The text was updated successfully, but these errors were encountered: