Skip to main content

OAuth 2.1 authorization server for Belgie

Project description

belgie-oauth-server

OAuth 2.1 authorization server package for Belgie.

Persistence

SimpleOAuthProvider keeps clients and tokens in memory. For production deployments, replace or extend the provider with persistent storage.

SimpleOAuthProvider also keeps client secrets in memory and is intended for development/testing. Production deployments should use a provider that stores secrets securely.

Resource Parameter Compatibility

The OAuth server now enforces strict resource semantics. If clients send a resource parameter without a configured OAuth resource (resources=[OAuthResource(...)]), authorize/token requests return invalid_target.

To migrate existing clients:

  • Configure a resource with resources=[OAuthResource(...)].
  • Or stop sending the resource parameter.

Dynamic Client Registration

If allow_dynamic_client_registration=True, Belgie serves POST /auth/oauth/register for OAuth Dynamic Client Registration.

If allow_unauthenticated_client_registration=True, anonymous registration is allowed for both:

  • public clients (token_endpoint_auth_method="none")
  • confidential clients (client_secret_post, client_secret_basic, or omitted auth method)

When the auth method is omitted, Belgie preserves provider-side defaulting and registers the client as client_secret_post.

This setting is intentionally permissive. Any anonymous caller can register a confidential client and receive a client secret, so treat it as a development or compatibility escape hatch unless you have separate controls around DCR.

ID Token Signing for Public Clients

id_token signing and verification use the client secret-derived key for confidential clients. Public clients (with token_endpoint_auth_method="none") use a server fallback signing secret instead.

This keeps RP-initiated logout working for public clients while still requiring normal OIDC claim validation. iss and aud are always checked when validating id_token_hint at /end-session.

Custom Login and Signup Pages

Use login_url and signup_url to point the OAuth server at app-owned pages:

from typing import Annotated

from fastapi import Depends, Request
from fastapi.responses import RedirectResponse

from belgie import BelgieClient
from belgie.oauth.server import OAuthServer, OAuthServerClient
from belgie_oauth_server.utils import construct_redirect_uri

oauth_plugin = belgie.add_plugin(
    OAuthServer(
        login_url="/login",
        signup_url="/signup",
        client_id="demo-client",
        client_secret="demo-secret",
        redirect_uris=["http://localhost:3030/callback"],
    ),
)


@app.get("/login")
async def login(
    request: Request,
    oauth: Annotated[OAuthServerClient, Depends(oauth_plugin)],
):
    context = await oauth.resolve_login_context(request)
    if context.intent == "create":
        return RedirectResponse(url=construct_redirect_uri("/signup", state=context.state), status_code=302)
    return RedirectResponse(url=construct_redirect_uri("/login/google", state=context.state), status_code=302)


@app.get("/signup")
async def signup(
    request: Request,
    oauth: Annotated[OAuthServerClient, Depends(oauth_plugin)],
    client: Annotated[BelgieClient, Depends(belgie)],
):
    context = await oauth.resolve_login_context(request)
    response = RedirectResponse(url=context.return_to, status_code=302)
    _user, session = await client.sign_up("dev@example.com", request=request)
    return client.create_session_cookie(session, response)

When prompt=create is present on /authorize, signup_url is preferred; otherwise login_url is used. prompt=create falls back to login_url if signup_url is not configured.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

belgie_oauth_server-0.10.4.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

belgie_oauth_server-0.10.4-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file belgie_oauth_server-0.10.4.tar.gz.

File metadata

  • Download URL: belgie_oauth_server-0.10.4.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie_oauth_server-0.10.4.tar.gz
Algorithm Hash digest
SHA256 553c9d7f709ed4ccc6bd898d9ba0b16e9cf489ee97e5c2302c9467e67c607608
MD5 9520c2f3b3b5e60d92ef0c7fd158bd59
BLAKE2b-256 c371c42fbf6035eef70dd3678ee1467a686ebc5075c2d5f45e8ee592d0abc22a

See more details on using hashes here.

File details

Details for the file belgie_oauth_server-0.10.4-py3-none-any.whl.

File metadata

  • Download URL: belgie_oauth_server-0.10.4-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for belgie_oauth_server-0.10.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8aa72f73c7e620f9f4025ff69f2c71b62e5ecdae1c69750b8add7a27f427f8ac
MD5 f8cbaaf8720412155d2ad1e5a1076363
BLAKE2b-256 f9f7d9953da61a3016baa3cf0694459b53b4e2e670fc9fca9149b0b1bdb75d96

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page