From 13b572b7859ab72a80468656e0120b1fd0aa10fa Mon Sep 17 00:00:00 2001 From: Jack McCaffrey Date: Mon, 20 Jun 2022 15:11:55 +0100 Subject: [PATCH] AMB-1139: Added optional `auth_scope` param to `_SimulatedAuthFlow` authentication methods. --- api_test_utils/oauth_helper.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/api_test_utils/oauth_helper.py b/api_test_utils/oauth_helper.py index a091424..f13fd83 100644 --- a/api_test_utils/oauth_helper.py +++ b/api_test_utils/oauth_helper.py @@ -70,12 +70,12 @@ def _get_id_token_private_key(self): ) return self._read_file(_path) - async def get_authenticated_with_simulated_auth(self): + async def get_authenticated_with_simulated_auth(self, auth_scope: str = ""): """Get the code parameter value required to post to the oauth /token endpoint""" authenticator = _SimulatedAuthFlow( self.base_uri, self.client_id, self.redirect_uri ) - return await authenticator.authenticate() + return await authenticator.authenticate(auth_scope=auth_scope) def get_authenticated_with_mock_auth( self, user: str = "9999999999" @@ -310,13 +310,14 @@ def __init__(self, base_uri: str, client_id: str, redirect_uri: str): self.client_id = client_id self.redirect_uri = redirect_uri - async def _get_state(self, request_state: str) -> str: + async def _get_state(self, request_state: str, auth_scope: str = "") -> str: """Send an authorize request and retrieve the state""" params = { "client_id": self.client_id, "redirect_uri": self.redirect_uri, "response_type": "code", "state": request_state, + "scope": auth_scope, } async with APISessionClient(self.base_uri) as session: @@ -338,9 +339,9 @@ async def _get_state(self, request_state: str) -> str: assert state != request_state return state - async def authenticate(self, request_state: str = str(uuid4())) -> str: + async def authenticate(self, request_state: str = str(uuid4()), auth_scope: str = "") -> str: """Authenticate and retrieve the code value""" - state = await self._get_state(request_state) + state = await self._get_state(request_state, auth_scope=auth_scope) params = { "response_type": "code", "client_id": self.client_id,