Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 5e663b1

Browse files
teemukatajablankdots
authored andcommitted
check for scopes before parsing token
1 parent ff4151b commit 5e663b1

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

beacon_api/utils/validate.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,19 @@ async def token_middleware(request, handler):
185185
# the bona_fide_status is specific to ELIXIR Tokens
186186
#
187187
# Retrieve GA4GH Passports from /userinfo and process them into dataset permissions and bona fide status
188-
dataset_permissions, bona_fide_status = await get_ga4gh_permissions(token)
188+
bona_fide_status = False
189+
dataset_permissions = set()
190+
required_scopes = ['openid', 'ga4gh_passport_v1']
191+
token_scopes = decoded_data.get('scope').split(' ')
192+
LOG.info(f'Required scopes: {required_scopes}')
193+
LOG.info(f'Token scopes: {token_scopes}')
194+
LOG.info(f'Bona fide before: {bona_fide_status}')
195+
LOG.info(f'Permissions before: {dataset_permissions}')
196+
if all(scope in token_scopes for scope in required_scopes):
197+
dataset_permissions, bona_fide_status = await get_ga4gh_permissions(token)
189198
#
199+
LOG.info(f'Bona fide after: {bona_fide_status}')
200+
LOG.info(f'Permissions after: {dataset_permissions}')
190201
controlled_datasets = set()
191202
# currently we offer module for parsing GA4GH permissions, but multiple claims and providers can be utilised
192203
# by updating the set, meaning replicating the line below with the permissions function and its associated claim

0 commit comments

Comments
 (0)