2015-07-01 15:53:41 +00:00
|
|
|
try:
|
2016-08-08 17:24:07 +00:00
|
|
|
from urllib.parse import urlencode
|
2015-07-01 19:43:35 +00:00
|
|
|
except ImportError:
|
2016-08-08 17:24:07 +00:00
|
|
|
from urllib import urlencode
|
2016-08-08 18:20:47 +00:00
|
|
|
try:
|
|
|
|
from urllib.parse import parse_qs, urlsplit
|
|
|
|
except ImportError:
|
|
|
|
from urlparse import parse_qs, urlsplit
|
2015-03-12 15:42:52 +00:00
|
|
|
import uuid
|
2015-02-27 20:40:17 +00:00
|
|
|
|
2015-02-12 18:04:58 +00:00
|
|
|
from django.contrib.auth.models import AnonymousUser
|
2016-04-14 19:22:38 +00:00
|
|
|
from django.core.management import call_command
|
2015-02-11 18:37:51 +00:00
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.test import RequestFactory
|
|
|
|
from django.test import TestCase
|
2016-08-08 18:20:47 +00:00
|
|
|
from jwkest.jwt import JWT
|
2015-02-27 20:40:17 +00:00
|
|
|
|
2015-02-18 18:07:22 +00:00
|
|
|
from oidc_provider import settings
|
2016-08-11 22:05:13 +00:00
|
|
|
from oidc_provider.tests.app.utils import (
|
|
|
|
create_fake_user,
|
|
|
|
create_fake_client,
|
|
|
|
FAKE_CODE_CHALLENGE,
|
|
|
|
is_code_valid,
|
|
|
|
)
|
|
|
|
from oidc_provider.views import AuthorizeView
|
2015-02-11 18:37:51 +00:00
|
|
|
|
|
|
|
|
2015-02-19 18:45:51 +00:00
|
|
|
class AuthorizationCodeFlowTestCase(TestCase):
|
2015-03-11 17:36:52 +00:00
|
|
|
"""
|
2016-08-08 18:20:47 +00:00
|
|
|
Test cases for Authorize Endpoint using Code Flow.
|
2015-03-11 17:36:52 +00:00
|
|
|
"""
|
2015-02-11 18:37:51 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
2016-04-14 19:22:38 +00:00
|
|
|
call_command('creatersakey')
|
2015-02-11 18:37:51 +00:00
|
|
|
self.factory = RequestFactory()
|
|
|
|
self.user = create_fake_user()
|
|
|
|
self.client = create_fake_client(response_type='code')
|
2016-04-08 21:09:24 +00:00
|
|
|
self.client_public = create_fake_client(response_type='code', is_public=True)
|
2015-02-27 20:40:17 +00:00
|
|
|
self.state = uuid.uuid4().hex
|
2016-04-14 19:22:38 +00:00
|
|
|
self.nonce = uuid.uuid4().hex
|
|
|
|
|
2016-04-14 20:45:30 +00:00
|
|
|
def _auth_request(self, method, data={}, is_user_authenticated=False):
|
2016-04-14 19:22:38 +00:00
|
|
|
url = reverse('oidc_provider:authorize')
|
|
|
|
|
|
|
|
if method.lower() == 'get':
|
2016-04-14 20:45:30 +00:00
|
|
|
query_str = urlencode(data).replace('+', '%20')
|
2016-04-14 19:22:38 +00:00
|
|
|
if query_str:
|
|
|
|
url += '?' + query_str
|
|
|
|
request = self.factory.get(url)
|
|
|
|
elif method.lower() == 'post':
|
2016-04-14 20:45:30 +00:00
|
|
|
request = self.factory.post(url, data=data)
|
2016-04-14 19:22:38 +00:00
|
|
|
else:
|
|
|
|
raise Exception('Method unsupported for an Authorization Request.')
|
|
|
|
|
|
|
|
# Simulate that the user is logged.
|
|
|
|
request.user = self.user if is_user_authenticated else AnonymousUser()
|
|
|
|
|
|
|
|
response = AuthorizeView.as_view()(request)
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
2015-02-27 20:40:17 +00:00
|
|
|
def test_missing_parameters(self):
|
2015-02-11 18:37:51 +00:00
|
|
|
"""
|
|
|
|
If the request fails due to a missing, invalid, or mismatching
|
|
|
|
redirection URI, or if the client identifier is missing or invalid,
|
|
|
|
the authorization server SHOULD inform the resource owner of the error.
|
|
|
|
|
|
|
|
See: https://tools.ietf.org/html/rfc6749#section-4.1.2.1
|
|
|
|
"""
|
2016-04-14 19:22:38 +00:00
|
|
|
response = self._auth_request('get')
|
2015-02-11 18:37:51 +00:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
2015-02-11 20:38:37 +00:00
|
|
|
self.assertEqual(bool(response.content), True)
|
|
|
|
|
2015-02-27 20:40:17 +00:00
|
|
|
def test_invalid_response_type(self):
|
2015-02-11 20:38:37 +00:00
|
|
|
"""
|
|
|
|
The OP informs the RP by using the Error Response parameters defined
|
|
|
|
in Section 4.1.2.1 of OAuth 2.0.
|
|
|
|
|
|
|
|
See: http://openid.net/specs/openid-connect-core-1_0.html#AuthError
|
|
|
|
"""
|
|
|
|
# Create an authorize request with an unsupported response_type.
|
2016-04-14 20:45:30 +00:00
|
|
|
data = {
|
2015-02-27 20:40:17 +00:00
|
|
|
'client_id': self.client.client_id,
|
|
|
|
'response_type': 'something_wrong',
|
|
|
|
'redirect_uri': self.client.default_redirect_uri,
|
|
|
|
'scope': 'openid email',
|
|
|
|
'state': self.state,
|
2016-04-14 19:22:38 +00:00
|
|
|
}
|
2015-02-12 18:04:58 +00:00
|
|
|
|
2016-04-14 20:45:30 +00:00
|
|
|
response = self._auth_request('get', data)
|
2015-02-11 20:38:37 +00:00
|
|
|
|
|
|
|
self.assertEqual(response.status_code, 302)
|
|
|
|
self.assertEqual(response.has_header('Location'), True)
|
|
|
|
|
2015-02-12 18:04:58 +00:00
|
|
|
# Should be an 'error' component in query.
|
|
|
|
query_exists = 'error=' in response['Location']
|
|
|
|
self.assertEqual(query_exists, True)
|
|
|
|
|
2015-03-19 17:19:27 +00:00
|
|
|
def test_user_not_logged(self):
|
2015-02-12 18:04:58 +00:00
|
|
|
"""
|
|
|
|
The Authorization Server attempts to Authenticate the End-User by
|
|
|
|
redirecting to the login view.
|
|
|
|
|
|
|
|
See: http://openid.net/specs/openid-connect-core-1_0.html#Authenticates
|
|
|
|
"""
|
2016-04-14 20:45:30 +00:00
|
|
|
data = {
|
2015-02-27 20:40:17 +00:00
|
|
|
'client_id': self.client.client_id,
|
|
|
|
'response_type': 'code',
|
|
|
|
'redirect_uri': self.client.default_redirect_uri,
|
|
|
|
'scope': 'openid email',
|
|
|
|
'state': self.state,
|
2016-04-14 19:22:38 +00:00
|
|
|
}
|
2015-02-12 18:04:58 +00:00
|
|
|
|
2016-04-14 20:45:30 +00:00
|
|
|
response = self._auth_request('get', data)
|
2015-02-12 18:04:58 +00:00
|
|
|
|
|
|
|
# Check if user was redirected to the login view.
|
|
|
|
login_url_exists = settings.get('LOGIN_URL') in response['Location']
|
|
|
|
self.assertEqual(login_url_exists, True)
|
|
|
|
|
2015-03-19 17:19:27 +00:00
|
|
|
def test_user_consent_inputs(self):
|
2015-02-20 17:33:18 +00:00
|
|
|
"""
|
|
|
|
Once the End-User is authenticated, the Authorization Server MUST
|
|
|
|
obtain an authorization decision before releasing information to
|
|
|
|
the Client.
|
|
|
|
|
|
|
|
See: http://openid.net/specs/openid-connect-core-1_0.html#Consent
|
|
|
|
"""
|
2016-04-14 20:45:30 +00:00
|
|
|
data = {
|
2015-02-27 20:40:17 +00:00
|
|
|
'client_id': self.client.client_id,
|
2015-03-30 18:37:48 +00:00
|
|
|
'response_type': 'code',
|
2015-02-27 20:40:17 +00:00
|
|
|
'redirect_uri': self.client.default_redirect_uri,
|
2015-03-30 18:37:48 +00:00
|
|
|
'scope': 'openid email',
|
2015-02-27 20:40:17 +00:00
|
|
|
'state': self.state,
|
2016-04-07 14:45:35 +00:00
|
|
|
# PKCE parameters.
|
|
|
|
'code_challenge': FAKE_CODE_CHALLENGE,
|
|
|
|
'code_challenge_method': 'S256',
|
2016-04-14 19:22:38 +00:00
|
|
|
}
|
2015-02-13 13:44:09 +00:00
|
|
|
|
2016-04-14 20:45:30 +00:00
|
|
|
response = self._auth_request('get', data, is_user_authenticated=True)
|
2015-02-13 13:44:09 +00:00
|
|
|
|
2015-02-27 20:40:17 +00:00
|
|
|
# Check if hidden inputs exists in the form,
|
|
|
|
# also if their values are valid.
|
2015-02-19 18:45:51 +00:00
|
|
|
input_html = '<input name="{0}" type="hidden" value="{1}" />'
|
|
|
|
|
|
|
|
to_check = {
|
|
|
|
'client_id': self.client.client_id,
|
|
|
|
'redirect_uri': self.client.default_redirect_uri,
|
2015-03-30 18:37:48 +00:00
|
|
|
'response_type': 'code',
|
2016-04-07 14:45:35 +00:00
|
|
|
'code_challenge': FAKE_CODE_CHALLENGE,
|
|
|
|
'code_challenge_method': 'S256',
|
2015-02-19 18:45:51 +00:00
|
|
|
}
|
|
|
|
|
2015-07-01 19:43:35 +00:00
|
|
|
for key, value in iter(to_check.items()):
|
2015-07-01 20:20:16 +00:00
|
|
|
is_input_ok = input_html.format(key, value) in response.content.decode('utf-8')
|
2015-02-19 18:45:51 +00:00
|
|
|
self.assertEqual(is_input_ok, True,
|
2016-08-08 17:24:07 +00:00
|
|
|
msg='Hidden input for "' + key + '" fails.')
|
2015-02-27 20:40:17 +00:00
|
|
|
|
2015-03-19 17:19:27 +00:00
|
|
|
def test_user_consent_response(self):
|
2015-02-27 20:40:17 +00:00
|
|
|
"""
|
|
|
|
First,
|
|
|
|
if the user denied the consent we must ensure that
|
|
|
|
the error response parameters are added to the query component
|
|
|
|
of the Redirection URI.
|
|
|
|
|
|
|
|
Second,
|
|
|
|
if the user allow the RP then the server MUST return
|
|
|
|
the parameters defined in Section 4.1.2 of OAuth 2.0 [RFC6749]
|
|
|
|
by adding them as query parameters to the redirect_uri.
|
|
|
|
"""
|
2016-04-14 19:22:38 +00:00
|
|
|
data = {
|
2015-02-27 20:40:17 +00:00
|
|
|
'client_id': self.client.client_id,
|
|
|
|
'redirect_uri': self.client.default_redirect_uri,
|
2016-04-14 19:22:38 +00:00
|
|
|
'response_type': 'code',
|
2015-03-12 15:42:52 +00:00
|
|
|
'scope': 'openid email',
|
2015-02-27 20:40:17 +00:00
|
|
|
'state': self.state,
|
2016-04-07 14:45:35 +00:00
|
|
|
# PKCE parameters.
|
|
|
|
'code_challenge': FAKE_CODE_CHALLENGE,
|
|
|
|
'code_challenge_method': 'S256',
|
2015-02-27 20:40:17 +00:00
|
|
|
}
|
|
|
|
|
2016-04-14 19:22:38 +00:00
|
|
|
response = self._auth_request('post', data, is_user_authenticated=True)
|
2015-02-27 20:40:17 +00:00
|
|
|
|
|
|
|
# Because user doesn't allow app, SHOULD exists an error parameter
|
|
|
|
# in the query.
|
2015-03-06 15:56:35 +00:00
|
|
|
self.assertEqual('error=' in response['Location'], True,
|
2015-04-30 15:42:00 +00:00
|
|
|
msg='error param is missing in query.')
|
2015-03-06 15:56:35 +00:00
|
|
|
self.assertEqual('access_denied' in response['Location'], True,
|
2015-04-30 15:42:00 +00:00
|
|
|
msg='"access_denied" code is missing in query.')
|
2015-02-27 20:40:17 +00:00
|
|
|
|
|
|
|
# Simulate user authorization.
|
2016-08-08 17:24:07 +00:00
|
|
|
data['allow'] = 'Accept' # Will be the value of the button.
|
2015-02-27 20:40:17 +00:00
|
|
|
|
2016-04-14 19:22:38 +00:00
|
|
|
response = self._auth_request('post', data, is_user_authenticated=True)
|
2015-02-27 20:40:17 +00:00
|
|
|
|
2015-06-23 19:32:12 +00:00
|
|
|
is_code_ok = is_code_valid(url=response['Location'],
|
|
|
|
user=self.user,
|
|
|
|
client=self.client)
|
2015-03-06 15:56:35 +00:00
|
|
|
self.assertEqual(is_code_ok, True,
|
|
|
|
msg='Code returned is invalid.')
|
2015-02-27 20:40:17 +00:00
|
|
|
|
|
|
|
# Check if the state is returned.
|
|
|
|
state = (response['Location'].split('state='))[1].split('&')[0]
|
2015-03-06 15:56:35 +00:00
|
|
|
self.assertEqual(state == self.state, True,
|
|
|
|
msg='State change or is missing.')
|
2015-03-11 17:36:52 +00:00
|
|
|
|
2015-06-23 19:32:12 +00:00
|
|
|
def test_user_consent_skipped(self):
|
|
|
|
"""
|
|
|
|
If users previously gave consent to some client (for a specific
|
|
|
|
list of scopes) and because they might be prompted for the same
|
|
|
|
authorization multiple times, the server skip it.
|
|
|
|
"""
|
2016-04-14 19:22:38 +00:00
|
|
|
data = {
|
2015-06-23 19:32:12 +00:00
|
|
|
'client_id': self.client.client_id,
|
|
|
|
'redirect_uri': self.client.default_redirect_uri,
|
|
|
|
'response_type': 'code',
|
|
|
|
'scope': 'openid email',
|
|
|
|
'state': self.state,
|
|
|
|
'allow': 'Accept',
|
|
|
|
}
|
|
|
|
|
|
|
|
request = self.factory.post(reverse('oidc_provider:authorize'),
|
2016-04-14 19:22:38 +00:00
|
|
|
data=data)
|
2015-06-23 19:32:12 +00:00
|
|
|
# Simulate that the user is logged.
|
|
|
|
request.user = self.user
|
|
|
|
|
2016-02-01 17:34:39 +00:00
|
|
|
with self.settings(OIDC_SKIP_CONSENT_ALWAYS=True):
|
2016-04-14 19:22:38 +00:00
|
|
|
response = self._auth_request('post', data, is_user_authenticated=True)
|
2016-02-01 17:34:39 +00:00
|
|
|
|
|
|
|
self.assertEqual('code' in response['Location'], True,
|
|
|
|
msg='Code is missing in the returned url.')
|
|
|
|
|
2016-04-14 19:22:38 +00:00
|
|
|
response = self._auth_request('post', data, is_user_authenticated=True)
|
2015-06-23 19:32:12 +00:00
|
|
|
|
|
|
|
is_code_ok = is_code_valid(url=response['Location'],
|
|
|
|
user=self.user,
|
|
|
|
client=self.client)
|
2016-02-01 17:34:39 +00:00
|
|
|
self.assertEqual(is_code_ok, True, msg='Code returned is invalid.')
|
2015-06-23 19:32:12 +00:00
|
|
|
|
2016-04-14 19:22:38 +00:00
|
|
|
del data['allow']
|
|
|
|
response = self._auth_request('get', data, is_user_authenticated=True)
|
2015-06-23 19:32:12 +00:00
|
|
|
|
|
|
|
is_code_ok = is_code_valid(url=response['Location'],
|
|
|
|
user=self.user,
|
|
|
|
client=self.client)
|
2016-02-01 17:34:39 +00:00
|
|
|
self.assertEqual(is_code_ok, True, msg='Code returned is invalid or missing.')
|
2015-07-10 10:22:25 +00:00
|
|
|
|
|
|
|
def test_response_uri_is_properly_constructed(self):
|
2016-04-14 19:22:38 +00:00
|
|
|
data = {
|
2015-07-10 10:22:25 +00:00
|
|
|
'client_id': self.client.client_id,
|
|
|
|
'redirect_uri': self.client.default_redirect_uri + "?redirect_state=xyz",
|
|
|
|
'response_type': 'code',
|
|
|
|
'scope': 'openid email',
|
|
|
|
'state': self.state,
|
|
|
|
'allow': 'Accept',
|
|
|
|
}
|
|
|
|
|
2016-04-14 19:22:38 +00:00
|
|
|
response = self._auth_request('post', data, is_user_authenticated=True)
|
2015-07-28 18:54:52 +00:00
|
|
|
|
2016-04-14 19:22:38 +00:00
|
|
|
# TODO
|
2016-01-19 19:08:13 +00:00
|
|
|
|
2016-04-08 21:09:24 +00:00
|
|
|
def test_public_client_auto_approval(self):
|
|
|
|
"""
|
|
|
|
It's recommended not auto-approving requests for non-confidential clients.
|
|
|
|
"""
|
2016-04-14 20:45:30 +00:00
|
|
|
data = {
|
2016-04-08 21:09:24 +00:00
|
|
|
'client_id': self.client_public.client_id,
|
|
|
|
'response_type': 'code',
|
|
|
|
'redirect_uri': self.client_public.default_redirect_uri,
|
|
|
|
'scope': 'openid email',
|
|
|
|
'state': self.state,
|
2016-04-14 19:22:38 +00:00
|
|
|
}
|
2016-04-08 21:09:24 +00:00
|
|
|
|
|
|
|
with self.settings(OIDC_SKIP_CONSENT_ALWAYS=True):
|
2016-04-14 20:45:30 +00:00
|
|
|
response = self._auth_request('get', data, is_user_authenticated=True)
|
2016-04-08 21:09:24 +00:00
|
|
|
|
|
|
|
self.assertEqual('Request for Permission' in response.content.decode('utf-8'), True)
|
2016-01-19 19:08:13 +00:00
|
|
|
|
2016-04-14 20:45:30 +00:00
|
|
|
def test_prompt_parameter(self):
|
|
|
|
"""
|
|
|
|
Specifies whether the Authorization Server prompts the End-User for reauthentication and consent.
|
|
|
|
See: http://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
|
|
|
|
"""
|
|
|
|
data = {
|
|
|
|
'client_id': self.client.client_id,
|
|
|
|
'response_type': self.client.response_type,
|
|
|
|
'redirect_uri': self.client.default_redirect_uri,
|
|
|
|
'scope': 'openid email',
|
|
|
|
'state': self.state,
|
|
|
|
}
|
|
|
|
|
|
|
|
data['prompt'] = 'none'
|
|
|
|
|
|
|
|
response = self._auth_request('get', data)
|
|
|
|
|
|
|
|
# An error is returned if an End-User is not already authenticated.
|
|
|
|
self.assertEqual('login_required' in response['Location'], True)
|
|
|
|
|
|
|
|
response = self._auth_request('get', data, is_user_authenticated=True)
|
|
|
|
|
|
|
|
# An error is returned if the Client does not have pre-configured consent for the requested Claims.
|
|
|
|
self.assertEqual('interaction_required' in response['Location'], True)
|
2016-08-08 18:20:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AuthorizationImplicitFlowTestCase(TestCase):
|
|
|
|
"""
|
|
|
|
Test cases for Authorization Endpoint using Implicit Flow.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
call_command('creatersakey')
|
|
|
|
self.factory = RequestFactory()
|
|
|
|
self.user = create_fake_user()
|
|
|
|
self.client = create_fake_client(response_type='id_token token')
|
|
|
|
self.client_public = create_fake_client(response_type='id_token token', is_public=True)
|
|
|
|
self.client_no_access = create_fake_client(response_type='id_token')
|
|
|
|
self.client_public_no_access = create_fake_client(response_type='id_token', is_public=True)
|
|
|
|
self.state = uuid.uuid4().hex
|
|
|
|
self.nonce = uuid.uuid4().hex
|
|
|
|
|
|
|
|
def _auth_request(self, method, data={}, is_user_authenticated=False):
|
|
|
|
url = reverse('oidc_provider:authorize')
|
|
|
|
|
|
|
|
if method.lower() == 'get':
|
|
|
|
query_str = urlencode(data).replace('+', '%20')
|
|
|
|
if query_str:
|
|
|
|
url += '?' + query_str
|
|
|
|
request = self.factory.get(url)
|
|
|
|
elif method.lower() == 'post':
|
|
|
|
request = self.factory.post(url, data=data)
|
|
|
|
else:
|
|
|
|
raise Exception('Method unsupported for an Authorization Request.')
|
|
|
|
|
|
|
|
# Simulate that the user is logged.
|
|
|
|
request.user = self.user if is_user_authenticated else AnonymousUser()
|
|
|
|
|
|
|
|
response = AuthorizeView.as_view()(request)
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
def test_missing_nonce(self):
|
|
|
|
"""
|
|
|
|
The `nonce` parameter is REQUIRED if you use the Implicit Flow.
|
|
|
|
"""
|
|
|
|
data = {
|
|
|
|
'client_id': self.client.client_id,
|
|
|
|
'response_type': self.client.response_type,
|
|
|
|
'redirect_uri': self.client.default_redirect_uri,
|
|
|
|
'scope': 'openid email',
|
|
|
|
'state': self.state,
|
|
|
|
}
|
|
|
|
|
|
|
|
response = self._auth_request('get', data, is_user_authenticated=True)
|
|
|
|
|
|
|
|
self.assertEqual('#error=invalid_request' in response['Location'], True)
|
|
|
|
|
|
|
|
def test_id_token_token_response(self):
|
|
|
|
"""
|
|
|
|
Implicit client requesting `id_token token` receives both id token
|
|
|
|
and access token as the result of the authorization request.
|
|
|
|
"""
|
|
|
|
data = {
|
|
|
|
'client_id': self.client.client_id,
|
|
|
|
'redirect_uri': self.client.default_redirect_uri,
|
|
|
|
'response_type': self.client.response_type,
|
|
|
|
'scope': 'openid email',
|
|
|
|
'state': self.state,
|
|
|
|
'nonce': self.nonce,
|
|
|
|
'allow': 'Accept',
|
|
|
|
}
|
|
|
|
|
|
|
|
response = self._auth_request('post', data, is_user_authenticated=True)
|
|
|
|
|
|
|
|
self.assertIn('access_token', response['Location'])
|
|
|
|
self.assertIn('id_token', response['Location'])
|
|
|
|
|
|
|
|
# same for public client
|
|
|
|
data['client_id'] = self.client_public.client_id,
|
|
|
|
data['redirect_uri'] = self.client_public.default_redirect_uri,
|
|
|
|
data['response_type'] = self.client_public.response_type,
|
|
|
|
|
|
|
|
response = self._auth_request('post', data, is_user_authenticated=True)
|
|
|
|
|
|
|
|
self.assertIn('access_token', response['Location'])
|
|
|
|
self.assertIn('id_token', response['Location'])
|
|
|
|
|
|
|
|
def test_id_token_response(self):
|
|
|
|
"""
|
|
|
|
Implicit client requesting `id_token` receives
|
|
|
|
only an id token as the result of the authorization request.
|
|
|
|
"""
|
|
|
|
data = {
|
|
|
|
'client_id': self.client_no_access.client_id,
|
|
|
|
'redirect_uri': self.client_no_access.default_redirect_uri,
|
|
|
|
'response_type': self.client_no_access.response_type,
|
|
|
|
'scope': 'openid email',
|
|
|
|
'state': self.state,
|
|
|
|
'nonce': self.nonce,
|
|
|
|
'allow': 'Accept',
|
|
|
|
}
|
|
|
|
|
|
|
|
response = self._auth_request('post', data, is_user_authenticated=True)
|
|
|
|
|
|
|
|
self.assertNotIn('access_token', response['Location'])
|
|
|
|
self.assertIn('id_token', response['Location'])
|
|
|
|
|
|
|
|
# same for public client
|
|
|
|
data['client_id'] = self.client_public_no_access.client_id,
|
|
|
|
data['redirect_uri'] = self.client_public_no_access.default_redirect_uri,
|
|
|
|
data['response_type'] = self.client_public_no_access.response_type,
|
|
|
|
|
|
|
|
response = self._auth_request('post', data, is_user_authenticated=True)
|
|
|
|
|
|
|
|
self.assertNotIn('access_token', response['Location'])
|
|
|
|
self.assertIn('id_token', response['Location'])
|
|
|
|
|
|
|
|
def test_id_token_token_at_hash(self):
|
|
|
|
"""
|
|
|
|
Implicit client requesting `id_token token` receives
|
|
|
|
`at_hash` in `id_token`.
|
|
|
|
"""
|
|
|
|
data = {
|
|
|
|
'client_id': self.client.client_id,
|
|
|
|
'redirect_uri': self.client.default_redirect_uri,
|
|
|
|
'response_type': self.client.response_type,
|
|
|
|
'scope': 'openid email',
|
|
|
|
'state': self.state,
|
|
|
|
'nonce': self.nonce,
|
|
|
|
'allow': 'Accept',
|
|
|
|
}
|
|
|
|
|
|
|
|
response = self._auth_request('post', data, is_user_authenticated=True)
|
|
|
|
|
|
|
|
self.assertIn('id_token', response['Location'])
|
|
|
|
|
|
|
|
# obtain `id_token` portion of Location
|
|
|
|
components = urlsplit(response['Location'])
|
|
|
|
fragment = parse_qs(components[4])
|
|
|
|
id_token = JWT().unpack(fragment["id_token"][0].encode('utf-8')).payload()
|
|
|
|
|
|
|
|
self.assertIn('at_hash', id_token)
|
|
|
|
|
|
|
|
def test_id_token_at_hash(self):
|
|
|
|
"""
|
|
|
|
Implicit client requesting `id_token` should not receive
|
|
|
|
`at_hash` in `id_token`.
|
|
|
|
"""
|
|
|
|
data = {
|
|
|
|
'client_id': self.client_no_access.client_id,
|
|
|
|
'redirect_uri': self.client_no_access.default_redirect_uri,
|
|
|
|
'response_type': self.client_no_access.response_type,
|
|
|
|
'scope': 'openid email',
|
|
|
|
'state': self.state,
|
|
|
|
'nonce': self.nonce,
|
|
|
|
'allow': 'Accept',
|
|
|
|
}
|
|
|
|
|
|
|
|
response = self._auth_request('post', data, is_user_authenticated=True)
|
|
|
|
|
|
|
|
self.assertIn('id_token', response['Location'])
|
|
|
|
|
|
|
|
# obtain `id_token` portion of Location
|
|
|
|
components = urlsplit(response['Location'])
|
|
|
|
fragment = parse_qs(components[4])
|
|
|
|
id_token = JWT().unpack(fragment["id_token"][0].encode('utf-8')).payload()
|
|
|
|
|
|
|
|
self.assertNotIn('at_hash', id_token)
|