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

Remove query parameters from callback_url #17

Closed
wants to merge 2 commits into from

Conversation

wjordan
Copy link

@wjordan wjordan commented Sep 7, 2016

Because query parameter removal is needed for request_phase in addition to build_access_token, this PR overrides the callback_url parameter instead of build_access_token.

Otherwise, the oauth check will fail with the following error if any query parameters are included in the redirected request:

Authentication failure! invalid_credentials: OAuth2::Error, invalid_grant: The provided value for the 'redirect_uri' is not valid. The value must exactly match the redirect URI used to obtain the authorization code.
{"error":"invalid_grant","error_description":"The provided value for the 'redirect_uri' is not valid. The value must exactly match the redirect URI used to obtain the authorization code."}

query parameter removal is needed for `request_phase` in addition to `build_access_token`.
@coveralls
Copy link

coveralls commented Sep 7, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling afa2753 on wjordan:query_parameter_fix into 2617222 on joel:master.

wjordan added a commit to code-dot-org/code-dot-org that referenced this pull request Sep 7, 2016
@wjordan wjordan reopened this Sep 8, 2016
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling afa2753 on wjordan:query_parameter_fix into 2617222 on joel:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling afa2753 on wjordan:query_parameter_fix into 2617222 on joel:master.

@joel
Copy link
Owner

joel commented Sep 15, 2016

Thanks @wjordan can you add or change test?

@coveralls
Copy link

coveralls commented Oct 11, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling b35a57b on wjordan:query_parameter_fix into 2617222 on joel:master.

@wjordan
Copy link
Author

wjordan commented Oct 11, 2016

@joel added test, please take a look.

@mrj
Copy link

mrj commented Feb 2, 2017

Removing all query parameters from the callback URL removes any way for application parameters to be propagated through the auth. Windows Live OAuth supports using callback URLs with query parameters added to the registered callback URLs, but doesn't seem to support adding application state parameters to authorization code requests. And the alternative of using cookies is more fragile.

I've used the following modification on my Groove Music fork to preserve only the application parameters, allowing the callback parameters to remain the same through the auth:

redirect_uri = URI.parse(callback_url).tap { |uri| uri.query = Rack::Utils.parse_query(uri.query).reject { |k,v| %w(code state).include?(k) }.to_query }.to_s

necessitating requiring 'rack/utils' and 'active_support' in this strategy file.

Perhaps removing the code and state parameters with a regular expression would be more efficient, and definitely wouldn't mess with parameter order, which is important to keep the callback URL matched.

I'd do a PR, but can't yet work out how to do a second fork under the original name.

@joel
Copy link
Owner

joel commented Feb 2, 2017

@wjordan and @mrj okay guys, I guess the best options is to put some setting in this gem like that :

you can choose between several options :

  • To clean all query params
  • Leave all query params
  • Provide a list of keys you want to keep
  • Provide a list of keys you want to wipe out.

Like that we can cover all cases.

What do you think?

@mrj
Copy link

mrj commented Feb 2, 2017

Joel, always removing just the code and state keys from the callback (plus any dangling question mark) should ensure that the callbacks always match, whether or not the callback has app parameters.

@joel
Copy link
Owner

joel commented Feb 2, 2017

Well @mrj then give me a PR please

@mrj
Copy link

mrj commented Feb 3, 2017

Joel, as I said, a PR is difficult because I already have a very different fork. I'd have to make a fork branch with a restored strategy file.

Really, removing code and state parameters from the callback url should be done by the omniauth-oauth2 gem itself. There are a number of issues there that cover the callback parameters problem, and a change to remove all the query parameters, as was done here, was reversed. One patch attempts to remove just the code and state parameters.

So I'll comment on the most recent issue discussing this.

@joel joel mentioned this pull request Feb 6, 2017
@joel
Copy link
Owner

joel commented Feb 6, 2017

@joel joel closed this Feb 6, 2017
@mrj
Copy link

mrj commented Feb 13, 2017

My comment on this issue at omniauth-oauth2 is here.

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

4 participants