mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-10 04:19:37 +00:00
Allow token_info response to use 'scopes' key (#565)
This commit is contained in:
committed by
Henning Jacobs
parent
4486438e70
commit
a4cabb23ae
@@ -73,10 +73,11 @@ def validate_token_info(token_info, allowed_scopes):
|
|||||||
:type token_info: dict
|
:type token_info: dict
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
if isinstance(token_info['scope'], list):
|
scope = token_info.get('scope') or token_info.get('scopes')
|
||||||
user_scopes = set(token_info['scope'])
|
if isinstance(scope, list):
|
||||||
|
user_scopes = set(scope)
|
||||||
else:
|
else:
|
||||||
user_scopes = set(token_info['scope'].split())
|
user_scopes = set(scope.split())
|
||||||
logger.debug("... Scopes required: %s", allowed_scopes)
|
logger.debug("... Scopes required: %s", allowed_scopes)
|
||||||
logger.debug("... User scopes: %s", user_scopes)
|
logger.debug("... User scopes: %s", user_scopes)
|
||||||
if not allowed_scopes <= user_scopes:
|
if not allowed_scopes <= user_scopes:
|
||||||
|
|||||||
@@ -111,3 +111,8 @@ def test_checking_that_client_token_has_all_necessary_scopes(
|
|||||||
headers = {"Authorization": "Bearer has_myscope_otherscope"}
|
headers = {"Authorization": "Bearer has_myscope_otherscope"}
|
||||||
response = app_client.get('/v1.0/more-than-one-scope', headers=headers) # type: flask.Response
|
response = app_client.get('/v1.0/more-than-one-scope', headers=headers) # type: flask.Response
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
# has all necessary scopes but under key 'scopes'
|
||||||
|
headers = {"Authorization": "Bearer has_scopes_in_scopes_with_s"}
|
||||||
|
response = app_client.get('/v1.0/more-than-one-scope', headers=headers) # type: flask.Response
|
||||||
|
assert response.status_code == 200
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ def oauth_requests(monkeypatch):
|
|||||||
return FakeResponse(200, '{"uid": "test-user", "scope": ["myscope", "otherscope"]}')
|
return FakeResponse(200, '{"uid": "test-user", "scope": ["myscope", "otherscope"]}')
|
||||||
if token in ["300", "is_not_invalid"]:
|
if token in ["300", "is_not_invalid"]:
|
||||||
return FakeResponse(404, '')
|
return FakeResponse(404, '')
|
||||||
|
if token == "has_scopes_in_scopes_with_s":
|
||||||
|
return FakeResponse(200, '{"uid": "test-user", "scopes": ["myscope", "otherscope"]}')
|
||||||
return url
|
return url
|
||||||
|
|
||||||
monkeypatch.setattr('connexion.decorators.security.session.get', fake_get)
|
monkeypatch.setattr('connexion.decorators.security.session.get', fake_get)
|
||||||
|
|||||||
Reference in New Issue
Block a user