Skip to content

Commit

Permalink
Merge pull request #61 from NHSDigital/amb-1139-add-scope-selection-t…
Browse files Browse the repository at this point in the history
…o-simulated-auth

AMB-1139: Added optional auth_scope param to _SimulatedAuthFlow authentication
  • Loading branch information
ChewieCB authored Jun 20, 2022
2 parents c36424d + 13b572b commit 375a5f5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions api_test_utils/oauth_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand Down

0 comments on commit 375a5f5

Please sign in to comment.