-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
401 Unauthorized response doesn't contain WWW-Authenticate header #917
Comments
Thanks for this bug report! This sounds like something we could enable by default as you say. What would be a reasonable value to put in the authenticate header if one isn't set? Would you be interested in contributing this? I think it's be as simple as changing the behaviour of the DefaultHTTPError method as you say. We could detect this error code and set the header to a default value and also allow the user the configure the string value returned. What can I do to help you make this a reality? |
Thanks for the quick reply! Yes I'm interested in contributing this. I'm not sure if we can set a reasonable default value though, I think we might need to rely on a user configured value. I didn't work with grpc-gateway a lot yet, so I don't know where the user typically passes configuration in a programmatical way. Maybe as a |
That would be the usual way, yes. Obviously, those are all optional, so the only other option is to only return this header when the user has supplied an option, which is still in violation of the HTTP spec 😢. Another alternative altogether is to introduce an automatic translation of some magic gRPC metadata value to the What do you think? |
I didn't work with gRPC metadata yet. It sounds to be more flexible when you can set it in a different way for each returned error instead of having to configure it up front when creating the SeverMux. On the other hand this might make it more verbose as well, having to set that with each One requirement to keep in mind is that within a single app multiple authentication schemes could be supported. For example it's probably common that a web service accepts |
I think setting the header automatically for when we return 401, but allowing the user to override the content via a magic gRPC metadata value seems best. That would make us compliant with the spec, which I think is a reasonable excuse for breaking backwards compatibility in this case. Would you be interested in contributing this? I could help you get started. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
So this got marked as stale, but 401 responses still violate the RFC by not returning this header, which makes this rather timeless until it's fixed. Can it be reopened? :-) |
Hello, I'm here from
|
Hi! I'm really pleased that you want to contribute to the project. I think the first step to making a contribution is to create a failing test, so that we can assert the behavior we expect. It should be pretty straightforward to add in these places:
Once we have a failing test, we can start thinking about how to implement a fix. It will probably be somewhere in https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/handler.go#L134 and https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/handler.go#L19. I hope that helps. Let me know if you have any more questions. You could also reach out in the #grpc-gateway channel on Gophers slack. |
Thank you very much for your kind instruction. It helped me a lot. |
I asked in the official gRPC Gitter channel, but didn't get a response so far: https://gitter.im/grpc/grpc?at=5ca0e2c1016a930a453cdc6d
Working on lightningnetwork/lnd#2332, where this question came up.
Maybe related to grpc-gateway issues #4, #221 and #309.
Steps you follow to reproduce the error:
When returning a
code.Unauthenticated
gRPC error, grpc-gateway maps this to a response with a 401 Unauthorized HTTP status code.The response doesn't contain a WWW-Authenticate error though.
What did you expect to happen instead:
According to the HTTP specification https://tools.ietf.org/html/rfc7235#section-3.1, a 401 Unauthorized response "MUST" be accompanied by a WWW-Authenticate header.
I understand that no static value like
WWW-Authenticate: Basic realm="simple"
can be used, as it completely depends on the used authentication scheme, but maybe there can be a way to easily configure this when setting up the gateway?I know that error responses can be customized (apparently in two different ways: via response forwarder and via custom error handler), but shouldn't there be a way for grpc-gateway to adhere to the HTTP specification by default?
Also, from my understanding you can't just add a header in those response customizations, but instead you have to create a complete response, which could lead to inconsistent responses or breaking changes, but I'm not sure about this.
What's your theory on why it isn't working:
I think setting the WWW-Authenticate header is just not implemented and I didn't find an easy way to set one (other than using one of the above mentioned response customizations).
I think the implementation is this one:
grpc-gateway/runtime/errors.go
Line 88 in 7aca14d
The text was updated successfully, but these errors were encountered: