Skip to main content

authx-identity

Standalone OpenID Connect (OIDC) identity microservice and Django client for application identity integration.

authx-identity provides a standalone FastAPI identity service together with a small Django client library.

AuthX is designed to be an independent identity authority that can be integrated into Django applications and other backend systems.

Features

  • OIDC-style identity endpoints
  • Email/password authentication
  • SSO identity support
  • RS256 JWT access and refresh tokens
  • JWKS public-key endpoint
  • Local JWT verification
  • Server-to-server identity management API
  • Django client library
  • Stateless token validation
  • PostgreSQL persistence
  • Alembic migrations
  • Configurable JWT issuer and audience
  • Provider-independent consumer architecture

Architecture

AuthX is the identity and JWT authority.

                    AuthX
                      │
          ┌───────────┴───────────┐
          │                       │
       JWT signing             Identity
          │                       │
          ▼                       ▼
     Access tokens          User identities
          │
          ▼
   Consumer applications
          │
          └── verify locally
              using JWKS

A consuming application does not need the AuthX private key.

The private signing key remains exclusively inside AuthX.

Requirements

  • Python 3.11 or later
  • PostgreSQL
  • FastAPI
  • SQLAlchemy
  • Alembic

A Django application using the client additionally requires Django.

Installation

Install the AuthX package:

pip install authx-identity

For Django consumers:

pip install "authx-identity[django]"

Running AuthX

Create a local environment:

cp env.example .env

Generate a new RSA key pair:

openssl genrsa -out jwt_private.pem 2048

openssl rsa \
  -in jwt_private.pem \
  -pubout \
  -out jwt_public.pem

Validate the private key:

openssl rsa -in jwt_private.pem -check -noout

Expected:

RSA key ok

Verify the public key:

openssl rsa \
  -in jwt_private.pem \
  -pubout \
  -outform PEM | diff - jwt_public.pem

No output indicates a matching public key.

Convert the PEM files into .env values:

awk 'NF {printf "%s\\n", $0}' jwt_private.pem
awk 'NF {printf "%s\\n", $0}' jwt_public.pem

Configure:

JWT_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"
JWT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----"

JWT_ALGORITHM=RS256
JWT_ISSUER=https://auth.example.com
JWT_AUDIENCE=your-application

AUTHX_SERVICE_TOKEN=<strong-random-secret>

Run migrations:

alembic upgrade head

Start AuthX:

uvicorn authx.main:app --host 0.0.0.0 --port 8100

Django integration

Configure the Django application with the AuthX service location and verification parameters:

AUTHX_BASE_URL = "https://auth.example.com"
AUTHX_SERVICE_TOKEN = "..."

AUTHX_JWT_ALGORITHM = "RS256"
AUTHX_JWT_ISSUER = "https://auth.example.com"
AUTHX_JWT_AUDIENCE = "your-application"

The service token is required only for trusted backend calls to AuthX's internal API.

The Django application does not require the AuthX private key.

Identity management

Create or look up identities through the client:

from authx_client import AuthXClient, AuthXConflictError

client = AuthXClient()

try:
    identity = client.create_identity(
        email="user@example.com",
        username="user",
        password="...",
    )
except AuthXConflictError:
    identity = client.get_by_email("user@example.com")

JWT verification

Consumers should verify AuthX tokens locally.

from authx_client import AuthXJWT

payload = AuthXJWT.decode(token)
identity_id = AuthXJWT.get_identity_id(token)

JWT verification validates:

  • signature
  • algorithm
  • issuer
  • audience
  • token validity

The consumer can use AuthX's JWKS endpoint to obtain the public signing key.

Public API

Method Endpoint Purpose
GET /.well-known/openid-configuration OIDC discovery
GET /jwks Public signing keys
POST /token Issue tokens
POST /token/refresh Refresh tokens
GET /userinfo Identity information

Internal API

Method Endpoint Purpose
POST /internal/identities Create identity
GET /internal/identities/{id} Retrieve identity
GET /internal/identities/by-email/{email} Find identity by email
GET /internal/identities/by-sso/lookup Find SSO identity
PATCH /internal/identities/{id} Update identity
DELETE /internal/identities/{id} Soft-delete identity

Internal endpoints require X-Service-Token and are intended for trusted backend services.

Configuration

Variable Description
APP_ENV Runtime environment
APP_HOST Service bind host
APP_PORT Service port
APP_BASE_URL AuthX service URL
DATABASE_URL Async PostgreSQL URL
DATABASE_URL_SYNC Sync PostgreSQL URL
JWT_PRIVATE_KEY RSA private signing key
JWT_PUBLIC_KEY RSA public verification key
JWT_ALGORITHM JWT algorithm
JWT_ACCESS_TOKEN_EXPIRE_MINUTES Access-token lifetime
JWT_REFRESH_TOKEN_EXPIRE_DAYS Refresh-token lifetime
JWT_ISSUER JWT issuer
JWT_AUDIENCE JWT audience
AUTHX_SERVICE_TOKEN Internal API credential
CORS_ORIGINS Allowed browser origins

JWT_ISSUER and JWT_AUDIENCE must be explicitly configured for every deployment.

Security

Never commit:

  • .env
  • RSA private keys
  • service tokens
  • database passwords

The AuthX private key must remain inside the AuthX deployment.

Consumer applications should use JWKS/public-key verification rather than receiving the private signing key.

License

MIT.

Download files

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

Source Distribution

authx_identity-1.1.0.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

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

authx_identity-1.1.0-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file authx_identity-1.1.0.tar.gz.

File metadata

  • Download URL: authx_identity-1.1.0.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.16

File hashes

Hashes for authx_identity-1.1.0.tar.gz
Algorithm Hash digest
SHA256 3f47acac36e20b5d55f88497f76ac7fef85ed2da9d947759d0d460cc078488ab
MD5 ac66982b099c16783cef56ebef6eb7b8
BLAKE2b-256 9b3e41c21fd1d100f37e2bd8d7a540d4777ab402536100e7a27f7bee40bd558f

See more details on using hashes here.

File details

Details for the file authx_identity-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: authx_identity-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.16

File hashes

Hashes for authx_identity-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9cf58d75a01c7cd67c70182b6c50d1f9647c6db776f1152ba7d0f9cdc0b66c84
MD5 e3502182cf4a943920b89ba7d6966efd
BLAKE2b-256 a75fcb5bc1854a653b392e5f34888bfb4f40f041014dd00cc9c1d31a1950e0a5

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.1

2 files

This release

1.1.0 This release

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page