Skip to content

Commit

Permalink
Merge pull request #455 from bjmc/prompt_bug
Browse files Browse the repository at this point in the history
Fixes bug with 'prompt' parameter
  • Loading branch information
thedrow committed Mar 19, 2017
2 parents d2c7be6 + 8d217d0 commit 30cbfa4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
7 changes: 6 additions & 1 deletion oauthlib/oauth2/rfc6749/grant_types/openid_connect.py
Expand Up @@ -293,10 +293,15 @@ def openid_authorization_validator(self, request):
msg = "Session user does not match client supplied user."
raise LoginRequired(request=request, description=msg)

prompt = []
if request.prompt:
prompt = request.prompt
if hasattr(prompt, 'split'):
prompt = prompt.split()

request_info = {
'display': request.display,
'prompt': request.prompt.split() if request.prompt else [],
'prompt': prompt,
'ui_locales': request.ui_locales.split() if request.ui_locales else [],
'id_token_hint': request.id_token_hint,
'login_hint': request.login_hint,
Expand Down
50 changes: 50 additions & 0 deletions tests/oauth2/rfc6749/endpoints/test_prompt_handling.py
@@ -0,0 +1,50 @@
from __future__ import absolute_import, unicode_literals
try:
from urllib.parse import urlencode
except ImportError:
from urllib import urlencode

import mock

from ....unittest import TestCase
from oauthlib.oauth2.rfc6749.tokens import BearerToken
from oauthlib.oauth2.rfc6749.grant_types import OpenIDConnectAuthCode
from oauthlib.oauth2.rfc6749.endpoints.authorization import AuthorizationEndpoint

class OpenIDConnectEndpointTest(TestCase):

def setUp(self):
self.mock_validator = mock.MagicMock()
self.mock_validator.authenticate_client.side_effect = self.set_client
grant = OpenIDConnectAuthCode(request_validator=self.mock_validator)
bearer = BearerToken(self.mock_validator)
self.endpoint = AuthorizationEndpoint(grant, bearer,
response_types={'code': grant})
params = {
'prompt': 'consent',
'state': 'abc',
'redirect_uri': 'https://a.b/cb',
'response_type': 'code',
'client_id': 'abcdef',
'scope': 'hello openid'
}
self.url = 'http://a.b/path?' + urlencode(params)

def set_client(self, request):
request.client = mock.MagicMock()
request.client.client_id = 'mocked'
return True

@mock.patch('oauthlib.common.generate_token')
def test_authorization_endpoint_handles_prompt(self, generate_token):
generate_token.return_value = "MOCK_CODE"
# In the GET view:
scopes, creds = self.endpoint.validate_authorization_request(self.url)
# In the POST view:
creds['scopes'] = scopes
h, b, s = self.endpoint.create_authorization_response(self.url,
credentials=creds)
expected = 'https://a.b/cb?state=abc&code=MOCK_CODE'
self.assertURLEqual(h['Location'], expected)
self.assertEqual(b, None)
self.assertEqual(s, 302)

0 comments on commit 30cbfa4

Please sign in to comment.