Skip to main content

aws-lambda-pyauthlib

https://img.shields.io/pypi/status/aws-lambda-pyauthlib.svg https://travis-ci.org/oharaandrew314/aws-lambda-pyauthlib.svg?branch=master https://img.shields.io/pypi/v/aws-lambda-pyauthlib.svg https://img.shields.io/pypi/l/aws-lambda-pyauthlib.svg https://img.shields.io/pypi/pyversions/aws-lambda-pyauthlib.svg codecov.io

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, raise_401
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:
        raise_401()
    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

You can also return an arbitrary authorizer context, by passing kwargs into the UserInfo. A list of authorities is always required, but nothing is stopping you from using an empty list.

Go check out the examples!

Metadata

Release files for aws-lambda-pyauthlib 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-lambda-pyauthlib 0.2.2
File Size Uploaded Provenance Actions
aws-lambda-pyauthlib-0.2.2.tar.gz 4.6 kB Without provenance Details for aws-lambda-pyauthlib-0.2.2.tar.gz

Release files / aws-lambda-pyauthlib-0.2.2.tar.gz

Download URL aws-lambda-pyauthlib-0.2.2.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5787b323e519480408fd88a357b85b919ff63542ad93d37d94320a96f5caa554
BLAKE2b-256 checksum
How to use checksums
3ef7dc4d3a71d79e356da715df0e0b87bbb4e1127d6d8f5de44d2116fb23c749
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for aws-lambda-pyauthlib 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page