Skip to content

Commit

Permalink
finished jwt verification
Browse files Browse the repository at this point in the history
  • Loading branch information
costero-e committed Nov 24, 2023
1 parent 0e993a6 commit b6cc964
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 37 deletions.
2 changes: 1 addition & 1 deletion beacon/request/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
from beacon.utils.stream import json_stream
from beacon.db.datasets import get_datasets
from beacon.utils.auth import resolve_token, check_user
from beacon.utils.auth import resolve_token

LOG = logging.getLogger(__name__)

Expand Down
34 changes: 0 additions & 34 deletions beacon/utils/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,3 @@ async def resolve_token(token, requested_datasets_ids):
LOG.debug(auth_datasets)
return auth_datasets, True, username

async def check_user(access_token):
user = None
idp_user_info = idpu
lsaai_user_info = lsu
async with ClientSession(trust_env=True) as session:
headers = { 'Accept': 'application/json', 'Authorization': 'Bearer ' + access_token }
LOG.debug('Contacting %s', idp_user_info)
async with session.get(idp_user_info, headers=headers) as resp:
LOG.debug('Response %s', resp)
if resp.status == 200:
user = await resp.json()
LOG.error(user)
return user
else:
content = await resp.text()
LOG.error('Not a Keycloak token')
#LOG.error('Content: %s', content)
user = 'public'

if user == 'public':
async with ClientSession(trust_env=True) as session:
headers = { 'Accept': 'application/json', 'Authorization': 'Bearer ' + access_token }
LOG.debug('Contacting %s', lsaai_user_info)
async with session.get(lsaai_user_info, headers=headers) as resp:
LOG.debug('Response %s', resp)
if resp.status == 200:
user = await resp.json()
return user
else:
content = await resp.text()
LOG.error('Not a LS AAI token')
LOG.error('Content: %s', content)
user = 'public'
return user
2 changes: 0 additions & 2 deletions permissions/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ async def get_user_info(access_token):
for visa_dataset in visa_datasets:
try:
visa = jwt.decode(visa_dataset, options={"verify_signature": False}, algorithms=["RS256"])
LOG.debug(visa)
LOG.debug(visa["ga4gh_visa_v1"]["value"])
dataset_url = visa["ga4gh_visa_v1"]["value"]
dataset_url_splitted = dataset_url.split('/')
visa_dataset = dataset_url_splitted[-1]
Expand Down

0 comments on commit b6cc964

Please sign in to comment.