Skip to content

Commit 37a9c01

Browse files
committed
oidc authorization is using access token instead of id_token
1 parent d2cba17 commit 37a9c01

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

askbot/deps/django_authopenid/protocols/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def get_protocol(provider_name):
1313
client_secret=params['oidc_client_secret'],
1414
provider_url=params['oidc_provider_url'],
1515
authorization_function=params['oidc_authorization_function'],
16+
custom_scopes=params['oidc_custom_scopes'],
1617
trust_email=params['trust_email'])
1718

1819
raise NotImplementedError(f'Not implemented for protocol {protocol_type}')

askbot/deps/django_authopenid/protocols/oidc/protocol.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ def __init__(self, # pylint: disable=too-many-arguments
2424
provider_url=None,
2525
trust_email=False,
2626
authorization_function=None,
27+
custom_scopes=None,
2728
audience=None):
2829
self.protocol_type = 'oidc'
2930
self.audience = audience
3031
self.client_id = client_id
3132
self.client_secret = client_secret
3233
self.provider_url = provider_url
3334
self.authorization_function = authorization_function
35+
self.custom_scopes = custom_scopes
3436
self.trust_email = trust_email
3537
discovery = self.load_discovery_data()
3638
self.authenticate_url = discovery['authorization_endpoint']
@@ -48,12 +50,23 @@ def load_discovery_data(self):
4850
return discovery_data
4951

5052

53+
def get_scopes(self):
54+
"""Merges the default scopes with the custom scopes"""
55+
scopes = ['openid', 'email', 'profile']
56+
if self.custom_scopes:
57+
for scope in self.custom_scopes:
58+
if scope not in scopes:
59+
scopes.append(scope)
60+
61+
return ' '.join(scopes)
62+
63+
5164
def get_authentication_url(self, redirect_url, csrf_token=None):
5265
"""Returns url at which OpenId-Connect service starts the user authentication"""
5366
query_params = {
5467
'client_id': self.client_id,
5568
'redirect_uri': redirect_url,
56-
'scope': 'openid email profile',
69+
'scope': self.get_scopes(),
5770
'nonce': csrf_token,
5871
'response_type': 'code',
5972
'response_mode': 'query',

askbot/deps/django_authopenid/protocols/oidc/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ def complete_oidc_signin(request): #pylint: disable=too-many-return-statements
4242

4343
id_token = token_info["id_token"]
4444

45-
#access_token = token_info["access_token"]
4645
#if not oidc.is_access_token_valid(access_token):
4746
# return HttpResponseBadRequest("Access token is invalid")
4847

4948
auth_csrf_token = request.session.pop('auth_csrf_token')
5049
if not oidc.is_id_token_valid(id_token, auth_csrf_token):
5150
return HttpResponseBadRequest("ID token is invalid")
5251

53-
if not oidc.is_user_authorized(id_token):
52+
access_token = token_info["access_token"]
53+
if not oidc.is_user_authorized(access_token):
5454
return HttpResponseBadRequest("You do not have access to this resource")
5555

5656
user_id = oidc.get_user_id(id_token)

askbot/deps/django_authopenid/util.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@ def read_params(self):
337337
else:
338338
self.oidc_authorization_function = lambda parsed_token: True
339339

340+
if hasattr(self.mode, 'OIDC_CUSTOM_SCOPES'):
341+
self.oidc_custom_scopes = self.mod.OIDC_CUSTOM_SCOPES
342+
else:
343+
self.oidc_custom_scopes = []
344+
340345
if self.login_type.startswith('openid'):
341346
self.openid_endpoint = self.get_required_attr('OPENID_ENDPOINT', 'custom OpenID login')
342347
if self.login_type == 'openid-username':
@@ -361,7 +366,8 @@ def as_dict(self):
361366
'check_password', 'auth_endpoint', 'token_endpoint',
362367
'resource_endpoint', 'response_parser', 'token_transport',
363368
'trust_email', 'oidc_provider_url', 'oidc_client_id',
364-
'oidc_client_secret', 'oidc_audience', 'oidc_authorization_function'
369+
'oidc_client_secret', 'oidc_audience', 'oidc_authorization_function',
370+
'oidc_custom_scopes'
365371
)
366372
#some parameters in the class have different names from those
367373
#in the dictionary

0 commit comments

Comments
 (0)