Skip to content
This repository has been archived by the owner on Jun 29, 2019. It is now read-only.

Commit

Permalink
Merge pull request #38 from wndhydrnt/fix_scope_urlencode
Browse files Browse the repository at this point in the history
Fix scope parameter not being urlencoded
  • Loading branch information
wndhydrnt committed Mar 29, 2015
2 parents afa9d84 + c66ad7c commit 6b426c0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Improvements:
Bugfixes:

- Fix Resource Owner Grant responding with HTTP status code '500' in case an owner could not be authorized ([@wndhydrnt][])
- Fix "scope" parameter not being urlencoded ([@wndhydrnt][])

## 0.7.0

Expand Down
4 changes: 2 additions & 2 deletions oauth2/grant.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def _generate_location(self, code):
query = "code=" + code

if self.state is not None:
query += "&state=" + self.state
query += "&state=" + quote(self.state)

return "%s?%s" % (self.client.redirect_uri, query)

Expand Down Expand Up @@ -705,7 +705,7 @@ def _redirect_access_token(self, response, token):
format(self.client.redirect_uri, token)

if self.state is not None:
uri_with_fragment += "&state=" + self.state
uri_with_fragment += "&state=" + quote(self.state)

if self.scope_handler.send_back is True:
scopes_as_string = encode_scopes(self.scope_handler.scopes,
Expand Down
10 changes: 6 additions & 4 deletions oauth2/test/test_grant.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from mock import Mock, call, patch
import json
from oauth2.client_authenticator import ClientAuthenticator
from oauth2.compatibility import quote
from oauth2.test import unittest
from oauth2.web import Request, Response, ResourceOwnerGrantSiteAdapter, \
ImplicitGrantSiteAdapter, AuthorizationCodeGrantSiteAdapter
Expand Down Expand Up @@ -196,11 +197,11 @@ def test_process(self):
code = "abcd"
environ = {"session": "data"}
scopes = ["scope"]
state = "mystate"
state = "my%state"
redirect_uri = "https://callback"
user_data = {"user_id": 789}

location_uri = "%s?code=%s&state=%s" % (redirect_uri, code, state)
location_uri = "%s?code=%s&state=%s" % (redirect_uri, code, quote(state))

auth_code_store_mock = Mock(spec=AuthCodeStore)

Expand Down Expand Up @@ -793,6 +794,7 @@ def test_create_not_matching_response_type(self):
request_mock.get_param.assert_called_with("response_type")
self.assertEqual(result_class, None)


class ImplicitGrantHandlerTestCase(unittest.TestCase):
def test_process_redirect_with_token(self):
client_id = "abc"
Expand Down Expand Up @@ -848,11 +850,11 @@ def test_process_redirect_with_state(self):
ImplicitGrantHandler should include the value of the "state" query parameter from request in redirect
"""
redirect_uri = "http://callback"
state = "XHGFI"
state = "XH%GFI"
token = "tokencode"
user_data = ({}, 1)

expected_redirect_uri = "%s#access_token=%s&token_type=bearer&state=%s" % (redirect_uri, token, state)
expected_redirect_uri = "%s#access_token=%s&token_type=bearer&state=%s" % (redirect_uri, token, quote(state))

response_mock = Mock(spec=Response)

Expand Down

0 comments on commit 6b426c0

Please sign in to comment.