From cf58289f887d536a281099a6039c2c81affa43bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oriol=20L=C3=B3pez-Doriga?= Date: Mon, 30 Oct 2023 15:54:31 +0100 Subject: [PATCH] adding userinfo to introspect --- permissions/auth.py | 16 ++++++++++++++-- permissions/permissions.yml | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/permissions/auth.py b/permissions/auth.py index 1d38c970..ae60a1a3 100644 --- a/permissions/auth.py +++ b/permissions/auth.py @@ -58,12 +58,24 @@ async def get_user_info(access_token): content = await resp.text() dict_content = json.loads(content) user = dict_content - return user else: LOG.error('Content: %s', content) LOG.error('Invalid token') raise web.HTTPUnauthorized() - + + user = None + 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() + return user + else: + content = await resp.text() + LOG.error('Content: %s', content) + raise web.HTTPUnauthorized() diff --git a/permissions/permissions.yml b/permissions/permissions.yml index 849ad937..385f5e64 100644 --- a/permissions/permissions.yml +++ b/permissions/permissions.yml @@ -11,3 +11,4 @@ new_user: - GiaB usuari_creat: - hola +null: []