Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,34 @@ def test_public_route():

</details>

### 5. Get an access token for a connection

If you need to get an access token for an upstream idp via a connection, you can use the `get_access_token_for_connection` method on the underlying api_client:

```python
import asyncio

from auth0_fastapi_api import Auth0FastAPI

async def main():
auth0 = Auth0FastAPI(
domain="<AUTH0_DOMAIN>",
audience="<AUTH0_AUDIENCE>",
client_id="<AUTH0_CLIENT_ID>",
client_secret="<AUTH0_CLIENT_SECRET>",
)
connection = "my-connection" # The Auth0 connection to the upstream idp
access_token = "..." # The Auth0 access token to exchange

connection_access_token = await auth0.api_client.get_access_token_for_connection({"connection": connection, "access_token": access_token})
# The returned token is the access token for the upstream idp
print(connection_access_token)

asyncio.run(main())
```

More info https://auth0.com/docs/secure/tokens/token-vault

## Feedback

### Contributing
Expand Down
4 changes: 2 additions & 2 deletions fastapi_plugin/fast_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Auth0FastAPI:
mirroring the concept from TypeScript's Fastify plugin.
"""

def __init__(self, domain: str, audience: str, custom_fetch=None):
def __init__(self, domain: str, audience: str, client_id=None, client_secret=None, custom_fetch=None):
"""
domain: Your Auth0 domain (like 'my-tenant.us.auth0.com')
audience: API identifier from the Auth0 Dashboard
Expand All @@ -25,7 +25,7 @@ def __init__(self, domain: str, audience: str, custom_fetch=None):
raise ValueError("audience is required.")

self.api_client = ApiClient(
ApiClientOptions(domain=domain, audience=audience, custom_fetch=custom_fetch)
ApiClientOptions(domain=domain, audience=audience, client_id=client_id, client_secret=client_secret, custom_fetch=custom_fetch)
)

def require_auth(
Expand Down
Loading