Skip to content

descoped/authly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

71 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Authly

Build Status Test Status Coverage Python Version License: MIT Release

A production-ready OAuth 2.1 + OpenID Connect 1.0 authorization server built with FastAPI and PostgreSQL. Authly provides enterprise-grade security, comprehensive testing (439/439 tests passing), and professional administration tools.


πŸš€ Production Ready Features

βœ… Complete OAuth 2.1 + OIDC 1.0 Compliance - Full RFC implementation with PKCE
βœ… 500+ Tests Passing - 100% success rate with real integration testing
βœ… Enterprise Security - Two-layer admin system, rate limiting, audit logging
βœ… Production Architecture - Docker, monitoring, health checks, deployment guides
βœ… Professional CLI - Complete admin interface with API-first architecture
βœ… Developer Experience - Comprehensive docs, easy setup, embedded development mode


πŸ” OAuth 2.1 Authorization Server

Core Authorization Features

  • Authorization Code Flow with mandatory PKCE (Proof Key for Code Exchange)
  • Client Management for confidential and public OAuth clients
  • Token Revocation (RFC 7009) for immediate token invalidation
  • Server Discovery (RFC 8414) for automatic client configuration
  • Scope Management with granular permission control

Supported Grant Types

  • Authorization Code Grant with PKCE for third-party applications
  • Password Grant for trusted first-party applications
  • Refresh Token Grant for token renewal
  • Client Credentials Grant for service-to-service authentication

Security Standards Compliance

  • RFC 6749 - OAuth 2.0 Authorization Framework βœ…
  • RFC 7636 - Proof Key for Code Exchange (PKCE) βœ…
  • RFC 7009 - OAuth 2.0 Token Revocation βœ…
  • RFC 8414 - OAuth 2.0 Authorization Server Metadata βœ…

πŸ†” OpenID Connect 1.0

OIDC Core Features

  • ID Token Generation with RS256/HS256 signing algorithms
  • UserInfo Endpoint with scope-based claims filtering
  • JWKS Endpoint for token signature verification
  • OIDC Discovery with provider configuration metadata

ID Token Claims

  • Standard Claims - sub, aud, iss, exp, iat, auth_time, nonce
  • Profile Claims - name, given_name, family_name, email, email_verified
  • Custom Claims - Extensible claims processing based on requested scopes

OIDC Standards Compliance

  • OpenID Connect Core 1.0 - Complete implementation βœ…
  • OpenID Connect Discovery 1.0 - Provider metadata βœ…

πŸ›‘οΈ Enterprise Security

Authentication & Authorization

  • JWT Security - RS256/HS256 signing with proper validation and rotation
  • Password Security - bcrypt hashing with configurable work factors
  • Token Management - JTI tracking, rotation, and blacklisting
  • Session Security - Concurrent session control and timeout management

Admin Security Model

  • Two-Layer Security - Intrinsic authority (is_admin flag) + OAuth scopes
  • Bootstrap System - Solves IAM chicken-and-egg paradox
  • Granular Permissions - 8 admin scopes for fine-grained access control
  • API Restrictions - Admin API localhost-only with configurable access

System Security

  • Rate Limiting - Configurable protection with multiple backends
  • CORS Protection - Comprehensive CORS policies and security headers
  • Secret Management - Encrypted storage with automatic memory cleanup
  • Audit Logging - Complete administrative action tracking

πŸ‘₯ User Management

User Lifecycle

  • Registration & Verification - Complete user onboarding with email verification
  • Role-Based Access Control - Admin and user roles with privilege management
  • Profile Management - Comprehensive user profile CRUD operations
  • Account Security - Password reset, account lockout, and security monitoring

Admin Capabilities

  • User Administration - Create, update, delete, and manage user accounts
  • Permission Management - Assign and revoke admin privileges
  • Security Monitoring - Track user authentication and security events

βš™οΈ Professional CLI Administration

Unified CLI Interface

# Start Authly server
python -m authly serve

# Admin operations
python -m authly admin login
python -m authly admin client create --name "My App" --type public
python -m authly admin scope create --name read --description "Read access"
python -m authly admin status

Admin Commands

  • Authentication - login, logout, whoami with secure token storage
  • Client Management - Create, list, update, delete OAuth clients
  • Scope Management - Create, list, update, delete OAuth scopes
  • User Management - Admin user operations and privilege management
  • System Status - Health checks, configuration, and system information

API-First Architecture

  • HTTP API Backend - CLI uses REST API exclusively (no direct DB access)
  • Secure Authentication - JWT-based admin authentication with refresh tokens
  • Consistent Interface - All admin operations available via both CLI and API

πŸš€ Quick Start

Development Setup

# Clone and install
git clone <repository-url>
cd authly
uv sync --all-groups -U

# Start with embedded development server (includes PostgreSQL container)
uv run python -m authly serve --embedded --dev

# Access Authly at http://localhost:8000
# Admin CLI: uv run python -m authly admin --help

Production Deployment

# Using Docker
docker build -t authly .
docker run -p 8000:8000 \
  -e DATABASE_URL="postgresql://user:pass@host:5432/authly" \
  -e JWT_SECRET_KEY="your-secret-key" \
  authly

# Using UV
export DATABASE_URL="postgresql://user:pass@localhost:5432/authly"
export JWT_SECRET_KEY="your-secret-key"
uv run python -m authly serve

OAuth Client Setup

# Create OAuth client
uv run python -m authly admin login
uv run python -m authly admin client create \
  --name "My Application" \
  --type confidential \
  --redirect-uri "https://myapp.com/callback"

# Create scope
uv run python -m authly admin scope create \
  --name "read" \
  --description "Read access to user data"

πŸ“š Documentation

API Documentation

Administration

Development


πŸ” API Endpoints

OAuth 2.1 Endpoints

  • GET/POST /oauth/authorize - Authorization endpoint with consent UI
  • POST /oauth/token - Token exchange endpoint with all grant types
  • POST /oauth/revoke - Token revocation endpoint
  • GET /.well-known/oauth-authorization-server - OAuth discovery metadata

OpenID Connect Endpoints

  • GET /oidc/userinfo - UserInfo endpoint with claims filtering
  • GET /.well-known/jwks.json - JWKS endpoint for token verification
  • GET /.well-known/openid_configuration - OIDC discovery metadata

Authentication Endpoints

  • POST /auth/token - User authentication and token generation
  • POST /auth/refresh - Token refresh and rotation
  • POST /auth/logout - Token invalidation and logout

Admin API Endpoints

  • GET/POST /admin/clients - OAuth client management
  • GET/POST /admin/scopes - OAuth scope management
  • GET/POST /admin/users - User management (admin only)
  • GET /admin/status - System health and configuration

Health & Monitoring

  • GET /health - Application health check
  • GET /health/ready - Readiness probe for Kubernetes
  • GET /health/live - Liveness probe for Kubernetes

πŸ§ͺ Testing Excellence

Test Coverage

  • 500+ Tests Total - 100% passing (verified production quality)
  • Real Integration Testing - PostgreSQL testcontainers (no mocking)
  • Complete Flow Testing - End-to-end OAuth and OIDC flows
  • Security Testing - Authentication, authorization, and validation
  • API Testing - All endpoints with comprehensive scenarios

Testing Categories

  • OAuth 2.1 Tests (156 tests) - Authorization flows, PKCE, client management
  • OIDC 1.0 Tests (98 tests) - ID tokens, UserInfo, JWKS, discovery
  • Admin System Tests (85 tests) - CLI, API, security, authentication
  • Core Authentication Tests (67 tests) - JWT, passwords, tokens
  • User Management Tests (33 tests) - User lifecycle and management

Quality Standards

  • No Mocking - Real database and HTTP server integration testing
  • Comprehensive Coverage - All features, security scenarios, and error cases
  • Continuous Validation - 100% success rate maintained throughout development

πŸ—οΈ Architecture

Technology Stack

  • Python 3.11+ - Modern async/await with comprehensive type annotations
  • FastAPI - High-performance async web framework with automatic OpenAPI
  • PostgreSQL - Advanced database with UUID primary keys and proper indexing
  • Pydantic v2 - Modern data validation with constraints and serialization
  • UV - Modern, fast Python package manager and dependency resolver

Design Patterns

  • Package-by-Feature - Clean module organization with clear boundaries
  • Repository Pattern - Clean data access layer with async operations
  • Service Layer Pattern - Business logic separation with dependency injection
  • Factory Pattern - FastAPI app factory for different deployment modes
  • Strategy Pattern - Pluggable components (storage, rate limiting, secrets)

Security Architecture

  • Layered Security - Multiple security layers with defense in depth
  • Async-First Design - Scalable performance with modern Python patterns
  • Type Safety - Comprehensive type annotations and validation
  • Configuration Management - Flexible config with multiple providers

πŸ“Š Project Status

Implementation Status

  • βœ… OAuth 2.1 Complete - All endpoints, flows, and security features
  • βœ… OIDC 1.0 Complete - ID tokens, UserInfo, JWKS, discovery
  • βœ… Admin System Complete - CLI, API, security, user management
  • βœ… Production Ready - Docker, monitoring, deployment, documentation
  • βœ… Test Excellence - 439/439 tests passing with comprehensive coverage

Standards Compliance

  • βœ… 6 RFC Specifications implemented and validated
  • βœ… Security Best Practices - OWASP guidelines and threat modeling
  • βœ… Enterprise Features - Audit logging, rate limiting, monitoring
  • βœ… Developer Experience - Comprehensive docs, easy setup, great tooling

Next Phase Opportunities

  • Performance Optimization - Advanced caching and connection optimization
  • Enterprise Features - Multi-tenant support, SAML integration, LDAP
  • Advanced Security - FIDO2, WebAuthn, biometric authentication
  • Cloud Native - Kubernetes operators, service mesh integration

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


🀝 Contributing

We welcome contributions! Please see our contributing guidelines and code of conduct.

Development Setup

  1. Clone the repository
  2. Install dependencies: uv sync --all-groups -U
  3. Run tests: pytest
  4. Start development server: uv run python -m authly serve --embedded --dev

Development Commands

  • Linting: uv run ruff check .
  • Formatting: uv run ruff format .
  • Validate Renovate config: npx --yes --package renovate -- renovate-config-validator .github/renovate.json

Quality Standards

  • All code must include comprehensive tests
  • 100% test success rate required
  • Type annotations and documentation required
  • Security-first development practices

Authly - Production-ready OAuth 2.1 + OpenID Connect 1.0 authorization server with enterprise-grade security and comprehensive testing.