Skip to content

Commit

Permalink
Merge pull request #12 from FIAP-3SOAT-G15/fix-error-handling
Browse files Browse the repository at this point in the history
Fix: error handling
  • Loading branch information
mateus3009 authored Mar 19, 2024
2 parents 8fddf2c + bae4882 commit ad9d50b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/auth-authorizer/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
def lambda_handler(event, context):
print('event: ', event)


token = event['authorizationToken']
if token.startswith('Bearer '):
token = token.split(' ')[1]

headers = jwt.get_unverified_header(token)
key = [k for k in KEYS if k['kid'] == headers['kid']][0]
public_key = RSAAlgorithm.from_jwk(key)
claims = jwt.decode(token, public_key, algorithms = ['RS256'], audience = APP_CLIENT_ID)
print('claims: ', claims)
try:
headers = jwt.get_unverified_header(token)
key = [k for k in KEYS if k['kid'] == headers['kid']][0]
public_key = RSAAlgorithm.from_jwk(key)
claims = jwt.decode(token, public_key, algorithms = ['RS256'], audience = APP_CLIENT_ID)
print('claims: ', claims)
except Exception as e:
print('Error: ', e)
return generate_policy('user', 'Deny', event['methodArn'])

groups = claims.get('cognito:groups', [])
print('groups: ', groups)
Expand Down

0 comments on commit ad9d50b

Please sign in to comment.