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

URL Encoding issue in redirect_url check #460

Open
netmikey opened this issue Apr 14, 2017 · 8 comments
Open

URL Encoding issue in redirect_url check #460

netmikey opened this issue Apr 14, 2017 · 8 comments

Comments

@netmikey
Copy link

I am trying to use a redirect_url that contains query parameters with the Authorization Code Grant flow. The redirects in the browser succeed, here is what chrome is requesting:

http://127.0.0.1:8080/app_dev.php/oauth/v2/auth?client_id=39691&response_type=code&redirect_uri=http://127.0.0.1:8091/authResponse?continue%3Dhttp://localhost:4200/assets/oauth.html%26client_id%3D39691

So the value of redirect_uri is http://127.0.0.1:8091/authResponse?continue%3Dhttp://localhost:4200/assets/oauth.html%26client_id%3D39691.

What ends up in the oauth_auth_code storage however is the value http://127.0.0.1:8091/authResponse?continue=http://localhost:4200/assets/oauth.html&client_id=39691 -- note that this URL seems to have been url-decoded before storage.

Now, when my oauth client calls the /oauth/v2/token endpoint to retrieve a token from the code obtained above, the redirect_url comparison fails because the incoming URL is not url-decoded. Here is the part that fails: https://github.com/FriendsOfSymfony/oauth2-php/blob/master/lib/OAuth2.php#L892-L898
I extended the error message to include both: $input["redirect_uri"] and $authCode->getRedirectUri(), and here is what it says:

{"error":"redirect_uri_mismatch","error_description":"The redirect URI is missing or do not match. Input: http://127.0.0.1:8091/authResponse?continue%3Dhttp://localhost:4200/assets/oauth.html%26client_id%3D39691 / Stored: http://127.0.0.1:8091/authResponse?continue=http://localhost:4200/assets/oauth.html&client_id=39691"}

The solution would be to either store redirect URIs in their encoded form in the /oauth/v2/auth endpoint, or to url-decode the incoming redirect_uri in the /oauth/v2/token endpoint.

As it stands now, it looks like having query parameters in a redirect_uri doesn't work.

@Spomky
Copy link

Spomky commented Apr 16, 2017

I think your redirect uri should be http%3A%2F%2F127.0.0.1%3A8091%2FauthResponse%3Fcontinue%253Dhttp%3A%2F%2Flocalhost%3A4200%2Fassets%2Foauth.html%2526client_id%253D39691 when passed as a query parameter.

Could you try with this value?

@netmikey
Copy link
Author

netmikey commented Apr 16, 2017 via email

@Spomky
Copy link

Spomky commented Apr 16, 2017

This bundle and the library uses the urlencode function and not the rawurlencode one (which is compatible with the RFC3986).

@netmikey
Copy link
Author

netmikey commented Apr 16, 2017 via email

@netmikey
Copy link
Author

netmikey commented Apr 16, 2017 via email

@netmikey
Copy link
Author

I've submitted a PR to the oauth2-php repository which fixes the issue for me and doesn't break any tests. I'd love to get some feedback on this!

// cc @GuilhemN

@NeoBlack
Copy link

NeoBlack commented Jun 5, 2018

Any news on this issue? I run into the same problem, is there a workaround to fix it?

@raveesgohiel9
Copy link

raveesgohiel9 commented Jun 3, 2019

Hello, I still have the same problem. I keep on getting this error for a new client.
{"error":"redirect_uri_mismatch","error_description":"The redirect URI is mandatory and was not supplied."}

I did not have similar problem with the previous clients that I created. Is there any configuration that I must check to fix this problem?
I created the client through command line. Then I am using browser to send data in the URL and get a response code. I did this earlier and it has worked.

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

4 participants