Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/svaponi/pyauth0
Python utilities for Auth0
https://github.com/svaponi/pyauth0
auth0 auth0-jwt python python3
Last synced: 4 months ago
JSON representation
Python utilities for Auth0
- Host: GitHub
- URL: https://github.com/svaponi/pyauth0
- Owner: svaponi
- License: mit
- Created: 2022-04-27T15:16:55.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-21T10:58:55.000Z (7 months ago)
- Last Synced: 2024-09-28T23:21:11.741Z (4 months ago)
- Topics: auth0, auth0-jwt, python, python3
- Language: Python
- Homepage: https://svaponi.github.io/pyauth0/
- Size: 144 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# pyauth0
[![Test](https://github.com/svaponi/pyauth0/actions/workflows/run-tests.yml/badge.svg)](https://github.com/svaponi/pyauth0/actions/workflows/run-tests.yml)
[![Coverage Status](https://coveralls.io/repos/github/svaponi/pyauth0/badge.svg?branch=main)](https://coveralls.io/github/svaponi/pyauth0?branch=main)
[![PyPI version](https://badge.fury.io/py/pyauth0.svg)](https://badge.fury.io/py/pyauth0)Python utilities for [Auth0](https://auth0.com/).
- [Install](#install)
- [Usage](#usage)
- [Get a machine-to-machine token](#get-a-machine-to-machine-token)
- [Verify a token](#verify-a-token)
- [Contribute](#contribute)## Install
```shell
pip install pyauth0
```## Usage
### Get a machine-to-machine token
```python
import asyncio
import httpx
from pyauth0 import TokenProvidertoken_provider = TokenProvider(
issuer="your-domain.auth0.com",
audience="https://api.your-domain.com",
client_id="1234",
client_secret="secret"
)async def main():
authorization = await token_provider.get_authorization()
async with httpx.AsyncClient() as client:
# Machine to machine request
response = await client.get(
"https://api.your-domain.com",
headers={"authorization": authorization},
)
print(response.content)asyncio.run(main())
```### Verify a token
```python
import asynciofrom pyauth0 import TokenVerifier, Auth0Error
token_verifier = TokenVerifier(
issuer="your-domain.auth0.com",
audience="https://api.your-domain.com",
jwks_cache_ttl=60, # optional
)async def main():
try:
decoded_token = await token_verifier.verify(
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...."
)
except Auth0Error as error:
status_code = error.status_code # suggested status code (401 or 403)
code = error.code # auth0 error code (example "token_expired")
description = error.description # auth0 error description (example "Token is expired.")
raise errorclaim_value = decoded_token.payload.get("http://your-domain.com/claim_name", "default value")
asyncio.run(main())
```## Contribute
If you want to contribute, open a [GitHub Issue](https://github.com/svaponi/pyauth0/issues) and motivate your request.