Skip to main content

Python SDK for AuthGate — OAuth 2.0 authentication and token management

Project description

AuthGate Python SDK

PyPI Python CI License

Python SDK for AuthGate — OAuth 2.0 authentication and token management.

Installation

pip install go-authgate

With framework support:

pip install go-authgate[fastapi]
pip install go-authgate[flask]
pip install go-authgate[django]

Quick Start

from authgate import authenticate

client, token = authenticate(
    "https://auth.example.com",
    "my-client-id",
    scopes=["profile", "email"],
)

print(f"Access token: {token.access_token}")

Async Usage

from authgate import async_authenticate

client, token = await async_authenticate(
    "https://auth.example.com",
    "my-client-id",
    scopes=["profile", "email"],
)

Client Credentials (M2M)

from authgate.oauth import OAuthClient, Endpoints
from authgate.clientcreds import TokenSource, BearerAuth
import httpx

client = OAuthClient("my-service", endpoints, client_secret="secret")
ts = TokenSource(client, scopes=["api"])

# Auto-attaches Bearer token to every request
with httpx.Client(auth=BearerAuth(ts)) as http:
    resp = http.get("https://api.example.com/data")

Middleware

FastAPI

from fastapi import FastAPI, Depends
from authgate.middleware.fastapi import BearerAuth
from authgate.middleware.models import TokenInfo

app = FastAPI()
auth = BearerAuth(oauth_client)

@app.get("/protected")
async def protected(info: TokenInfo = Depends(auth)):
    return {"user": info.user_id}

Flask

from flask import Flask
from authgate.middleware.flask import bearer_auth, get_token_info

app = Flask(__name__)

@app.route("/protected")
@bearer_auth(oauth_client)
def protected():
    info = get_token_info()
    return {"user": info.user_id}

Development

make install    # uv sync --all-extras
make test
make lint
make typecheck

License

MIT

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

go_authgate-0.1.0.tar.gz (93.1 kB view details)

Uploaded Source

Built Distribution

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

go_authgate-0.1.0-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

Details for the file go_authgate-0.1.0.tar.gz.

File metadata

  • Download URL: go_authgate-0.1.0.tar.gz
  • Upload date:
  • Size: 93.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for go_authgate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 80069537e40504aac9b353d7f5867c41b170daa6e286d27510c54129e9677a68
MD5 5c20fa503ff098a9583b70062a20ff20
BLAKE2b-256 298eaf38d8d546f132d0b19bd181ffb19a8b51898dabe78a65119cde89fc8a02

See more details on using hashes here.

Provenance

The following attestation bundles were made for go_authgate-0.1.0.tar.gz:

Publisher: release.yml on go-authgate/sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file go_authgate-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: go_authgate-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 33.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for go_authgate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf0d86b20aeb8d5cb0065e42d21449f2efe7f0f9ee97be546a46fc96ea33b5f0
MD5 0cb90617424f0d9d005b052a6f28bdfa
BLAKE2b-256 7a180c938712318a5f88ea77b4174655d455f19b9e026f076bb6aefc708cf7fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for go_authgate-0.1.0-py3-none-any.whl:

Publisher: release.yml on go-authgate/sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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