A python helper library for AWS API Gateway Custom Authorizers
Project description
A python helper library for AWS API Gateway Custom Authorizers.
Installation
pip install aws-lambda-pyauthlib
or
pipenv install aws-lambda-pyauthlib
Quickstart
'''authorizer_handler.py'''
from pyauthlib import UserInfo, AuthPolicy, HttpMethod, parse_event
from my_auth_client import get_client
def lambda_handler(event, _context):
'''Exchanges access token for user_info and returns the policy.
Unauthorized users are denied all access.
Users are allowed read access to all resources.
Admins are allowed full access to all resources.
'''
event = parse_event(event)
identity = get_client().get_identity(event.access_token)
user_info = UserInfo(identity['user_id'], identity['grants'])
policy = AuthPolicy(user_info)
if not user_info:
policy.deny(event.arn(method=HttpMethod.ALL, resource='*'))
elif 'ROLE_ADMIN' in user_info.authorities:
policy.allow(event.arn(method=HttpMethod.ALL, resource='*'))
else:
policy.allow(event.arn(method=HttpMethod.GET, resource='*'))
return policy.build()
More Information
Go check out the examples!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for aws-lambda-pyauthlib-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03aa378dfc25a6f789ab280a83fae111765702892b943469d0607c5c2e8cd3da |
|
MD5 | 0f1cc0f287c22f51b072baa0d610c80a |
|
BLAKE2b-256 | c1f81dcf3309cc2ed68255f67519a88c247944b7ce6bcfaa0b85233467092581 |