Open menisy opened 3 years ago
Thanks for the detailed report @menisy, I will need to do some looking into things as I'm not sure off the bat what the correct behavior is. I'd be willing to review a PR and evaluating the risk of any changes if you have a suggestion in the short term
@BobbyMcWho thanks for the prompt response. I have something in mind, I will try to issue a PR soon.
I'm somewhat surprised that the extra params are causing issues, because I've used omniauth-okta before, and okta has some fairly strict redirect uri matching if I recall correctly
@BobbyMcWho according to omniauth-okta's implementation, they're overriding the callback_url
to include only full_host
and callback_path
and not the query_string
. This in itself is also not very accurate since the callback url could indeed contain query params which should be maintained through calls. My PR only ensures that whatever callback url was used in the request phase gets reused in the callback phase (which would still maintain query params that existed in the request phase, and not include the extra ones passed from the authorization server (i.e code
and state
)).
The spec is very clear that the redirect_uri
used in the code-token exchange must exactly match the one that was used to obtain the code during the authorization request.
I see that at least #70 and #93 are related to this.
With this update from Doorkeeper, existing authorization flows stopped working. This is no longer the case since this update on Doorkeeper was reverted.
However, it seemed to me that there is a strange behaviour when I was debugging to see why this was no longer working.
A couple of
pry
's later I figured out what's going on. I will use an example as it's a bit complicated to explain: Resource server onlocalhost:3000
Authorization server onlocalhost:5000
redirect_uri
on Doorkeeper (authorization server) side is:http://localhost:3000/auth/some_provider/callback
http://localhost:5000/oauth/authorize?client_id=some_client_id&&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%some_provider%2Fcallback&response_type=code&state=some_state
http://localhost:3000/auth/some_provider/callback?code=some_authorization_code&state=some_state
redirect_uri
using thiscallback_url
method defined inomniauth
which adds therequest.query_string
to thecallback_url
. So the code exchange request becomes:POST http://localhost:5000/oauth/token
with params:and this is where it is questionable whether the
code
andstate
should be replied back to the authorization server as part of theredirect_uri
even though they didn't originally exist in the request phase. And this is where the reverted update was facing an issue as it couldn't fully match theredirect_uri
with these extra query params against the one(s) defined on the authorization server during registration of the client.This is the source of it in
omniauth
, I honestly did not dive deep enough in the spec to know what is the expected behaviour, however, this behaviour doesn't look correct.