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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pip install auth0-server-python
If you’re using Poetry:

```shell
poetry install auth0-server-python
poetry add auth0-server-python
```

### 2. Create the Auth0 SDK client
Expand All @@ -40,7 +40,7 @@ auth0 = ServerClient(
client_secret='<AUTH0_CLIENT_SECRET>',
secret='<AUTH0_SECRET>',
authorization_params= {
redirect_uri: '<AUTH0_REDIRECT_URI>',
'redirect_uri': '<AUTH0_REDIRECT_URI>',
}
)
```
Expand Down
4 changes: 2 additions & 2 deletions examples/ClientInitiatedBackChannelLogin.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Before using backchannel authentication:
### Initiating Backchannel Authentication

```python
from auth0_server_python import ServerClient
from auth0_server_python.auth_server import ServerClient

# Initialize the Auth0 client
auth0 = ServerClient(
Expand Down Expand Up @@ -101,7 +101,7 @@ Read more above in [Configuring the Store](./ConfigureStore.md).

from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from auth0_server_python import ServerClient
from auth0_server_python.auth_server import ServerClient

app = FastAPI()

Expand Down
13 changes: 5 additions & 8 deletions examples/ConfigureStore.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ If you’re using `auth0-fastapi`, you already have:
2. **CookieTransactionStore** – stores short-lived transaction data (PKCE code_verifier) in another encrypted cookie.

```python
from store.abstract import StateStore, TransactionStore
from auth0_server_python.store import StateStore, TransactionStore

class StatelessStateStore(StateStore):
def __init__(self, secret: str, cookie_name: str = "_a0_session"):
Expand Down Expand Up @@ -98,9 +98,10 @@ A **stateful** approach stores only a **session ID** in the cookie, while the ac
### 3.1. Redis-Based Example
Let’s walk through a `RedisStateStore` that inherits from `StateStore`:
```python
import json
import aioredis
from typing import Any, Dict, Optional
from store.abstract import StateStore
from auth0_server_python.store import StateStore

class RedisStateStore(StateStore):
"""
Expand Down Expand Up @@ -133,7 +134,6 @@ class RedisStateStore(StateStore):
# encrypted_data = self.encrypt(session_id, state)
# await self.redis_client.set(session_id, encrypted_data)
# For demo, let's store it as JSON without encryption:
import json
await self.redis_client.set(session_id, json.dumps(state))

# Now set a cookie in the response with just the session_id
Expand Down Expand Up @@ -166,7 +166,6 @@ class RedisStateStore(StateStore):
return None

# If you used self.encrypt(...) on set, call self.decrypt(...) here.
import json
return json.loads(raw_data)

async def delete(
Expand Down Expand Up @@ -206,7 +205,6 @@ class RedisStateStore(StateStore):
for k in keys:
raw_data = await self.redis_client.get(k)
if raw_data:
import json
session_data = json.loads(raw_data)
# If your session_data stores an internal dict with `sid` or `sub`
internal = session_data.get("internal", {})
Expand Down Expand Up @@ -240,9 +238,10 @@ Now your user’s session data is in **Redis**, and only a minimal session ID is
If you prefer a **SQL database** for session data, here’s a `PostgresStateStore` example using [asyncpg](https://github.com/MagicStack/asyncpg).

```python
import json
import asyncpg
from typing import Any, Dict, Optional
from store.abstract import StateStore
from auth0_server_python.store import StateStore

class PostgresStateStore(StateStore):
"""
Expand Down Expand Up @@ -277,7 +276,6 @@ class PostgresStateStore(StateStore):
# Optionally encrypt `state`:
# encrypted_data = self.encrypt(session_id, state)
# For simplicity, store as JSON
import json
data_json = json.dumps(state)

# Insert or update the session
Expand Down Expand Up @@ -322,7 +320,6 @@ class PostgresStateStore(StateStore):
if not row:
return None
# If you used encryption, do self.decrypt(...)
import json
return json.loads(row["session_data"])

async def delete(
Expand Down
4 changes: 2 additions & 2 deletions examples/MultipleCustomDomains.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ See [Security Best Practices](#security-best-practices) for important guidance o
For applications with a single Auth0 domain:

```python
from auth0_server_python import ServerClient
from auth0_server_python.auth_server import ServerClient

client = ServerClient(
domain="login.yourapp.com", # Static string
Expand All @@ -34,7 +34,7 @@ client = ServerClient(
For MCD support, provide a domain resolver function that receives a `DomainResolverContext`:

```python
from auth0_server_python import ServerClient
from auth0_server_python.auth_server import ServerClient
from auth0_server_python.auth_types import DomainResolverContext

# Map your app hostnames to Auth0 custom domains
Expand Down
12 changes: 6 additions & 6 deletions examples/RetrievingData.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
The SDK's `get_user()` can be used to retrieve the current logged-in user:

```python
user = await serverClient.get_user();
user = await server_client.get_user()
```

### Passing Store Options

Just like most methods, `getUser` accept an argument that is used to pass to the configured Transaction and State Store:
Just like most methods, `get_user` accept an argument that is used to pass to the configured Transaction and State Store:

```python
store_options = {
Expand All @@ -27,7 +27,7 @@ Read more above in [Configuring the Store](./ConfigureStore.md).
The SDK's `get_session()` can be used to retrieve the current session data:

```python
session = await serverClient.get_session();
session = await server_client.get_session()
```

### Passing Store Options
Expand Down Expand Up @@ -58,7 +58,7 @@ In order to do this, the SDK needs access to a Refresh Token. By default, the SD

### Passing Store Options

Just like most methods, `getAccessToken` accept an argument that is used to pass to the configured Transaction and State Store:
Just like most methods, `get_access_token` accept an argument that is used to pass to the configured Transaction and State Store:

```python
store_options = {
Expand Down Expand Up @@ -225,7 +225,7 @@ token = await server_client.get_access_token(audience="https://api.example.com")

# Avoid unless necessary: Dynamic scopes increase session size
token = await server_client.get_access_token(
audience="https://api.example.com"
audience="https://api.example.com",
scope="openid profile email read:products write:products admin:all"
)
```
Expand All @@ -244,7 +244,7 @@ access_token_for_google = await server_client.get_access_token_for_connection(co
```

- `connection`: The connection for which an access token should be retrieved, e.g. `google-oauth2` for Google.
- `loginHint`: Optional login hint to inform which connection account to use, can be useful when multiple accounts for the connection exist for the same user.
- `login_hint`: Optional login hint to inform which connection account to use, can be useful when multiple accounts for the connection exist for the same user.

The SDK will cache the token internally, and return it from the cache when not expired. When no token is found in the cache, or the token is expired, calling `get_access_token_for_connection()` will call Auth0 to retrieve a new token and update the cache.

Expand Down
Loading