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

fix: redirect URI should be the last parameter #874

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions oauthlib/oauth2/rfc6749/parameters.py
Expand Up @@ -73,8 +73,6 @@ def prepare_grant_uri(uri, client_id, response_type, redirect_uri=None,
params = [(('response_type', response_type)),
(('client_id', client_id))]

if redirect_uri:
params.append(('redirect_uri', redirect_uri))
if scope:
params.append(('scope', list_to_scope(scope)))
if state:
Expand All @@ -87,6 +85,9 @@ def prepare_grant_uri(uri, client_id, response_type, redirect_uri=None,
if kwargs[k]:
params.append((str(k), kwargs[k]))

if redirect_uri:
params.append(('redirect_uri', redirect_uri))

return add_params_to_uri(uri, params)


Expand Down
11 changes: 4 additions & 7 deletions tests/oauth2/rfc6749/test_parameters.py
Expand Up @@ -37,13 +37,12 @@ def setUp(self):
self.auth_implicit_list_scope['scope'] = self.list_scope

auth_base_uri = ('https://server.example.com/authorize?response_type={0}'
'&client_id=s6BhdRkqt3&redirect_uri=https%3A%2F%2F'
'client.example.com%2Fcb&scope={1}&state={2}{3}')
'&client_id=s6BhdRkqt3&scope={1}&state={2}{3}'
'&redirect_uri=https%3A%2F%2Fclient.example.com%2Fcb')

auth_base_uri_pkce = ('https://server.example.com/authorize?response_type={0}'
'&client_id=s6BhdRkqt3&redirect_uri=https%3A%2F%2F'
'client.example.com%2Fcb&scope={1}&state={2}{3}&code_challenge={4}'
'&code_challenge_method={5}')
'&client_id=s6BhdRkqt3&scope={1}&state={2}{3}&code_challenge={4}'
'&code_challenge_method={5}&redirect_uri=https%3A%2F%2Fclient.example.com%2Fcb')

auth_grant_uri = auth_base_uri.format('code', 'photos', state, '')
auth_grant_uri_pkce = auth_base_uri_pkce.format('code', 'photos', state, '', 'code_challenge',
Expand Down Expand Up @@ -192,7 +191,6 @@ def setUp(self):
'&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA'
'&example_parameter=example_value')


def test_prepare_grant_uri(self):
"""Verify correct authorization URI construction."""
self.assertURLEqual(prepare_grant_uri(**self.auth_grant), self.auth_grant_uri)
Expand Down Expand Up @@ -269,7 +267,6 @@ def record_scope_change(sender, message, old, new):
signals.scope_changed.disconnect(record_scope_change)
del os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE']


def test_json_token_notype(self):
"""Verify strict token type parsing only when configured. """
self.assertEqual(parse_token_response(self.json_notype), self.json_notype_dict)
Expand Down