From 833194156567ba7506bf52ae78ebbad61845a80c Mon Sep 17 00:00:00 2001 From: Jatin Vasman Date: Sat, 13 Sep 2025 17:04:02 +0530 Subject: [PATCH 1/4] Add OIDC implementation with authentication and configuration support --- .env.example | 79 +++++++++ CHANGELOG.md | 15 ++ client/index.html | 6 + client/src/auth/Login.vue | 245 +++++++++++++++++++++++---- client/src/locales/de.json | 3 +- client/src/locales/en.json | 2 + client/src/locales/es.json | 3 +- client/src/locales/it.json | 3 +- client/src/router/bootstrap.ts | 11 +- client/src/router/index.ts | 26 ++- docker-compose.yml | 39 +++++ server/pyproject.toml | 3 + server/src/api/http/auth.py | 172 +++++++++++++++++++ server/src/app.py | 2 +- server/src/auth.py | 79 +-------- server/src/auth/__init__.py | 5 + server/src/auth/core.py | 88 ++++++++++ server/src/auth/oidc.py | 301 +++++++++++++++++++++++++++++++++ server/src/config/manager.py | 117 +++++++++++-- server/src/config/types.py | 64 +++++-- server/src/json.py | 15 +- server/src/mail/__init__.py | 2 +- server/src/pydantic_json.py | 22 +++ server/src/routes.py | 84 ++++++++- server/uv.lock | 93 +++++++++- 25 files changed, 1311 insertions(+), 168 deletions(-) create mode 100644 .env.example create mode 100644 docker-compose.yml create mode 100644 server/src/auth/__init__.py create mode 100644 server/src/auth/core.py create mode 100644 server/src/auth/oidc.py create mode 100644 server/src/pydantic_json.py diff --git a/.env.example b/.env.example new file mode 100644 index 000000000..30f9e428c --- /dev/null +++ b/.env.example @@ -0,0 +1,79 @@ +# PlanarAlly Environment Configuration +# Copy this file to .env and configure your values + +# Python environment +PYTHONPATH=./server/src +MYPYPATH=./server/src + +# ============================================================================= +# GENERAL CONFIGURATION +# ============================================================================= + +# The client url is the full URL to the landing page of the application +PA_CLIENT_URL=https://your-domain.com/ + +# Allow users to sign up for new accounts +PA_ALLOW_SIGNUPS=true + +# Enable username/password login (set to false to use only OIDC) +PA_USERNAME_PASS=true + +# Enable exporting of campaigns +PA_ENABLE_EXPORT=true + +# ============================================================================= +# WEBSERVER CONFIGURATION +# ============================================================================= + +# Host and port for the webserver +PA_WEBSERVER_HOST=0.0.0.0 +PA_WEBSERVER_PORT=8000 + +# CORS allowed origins +PA_CORS_ALLOWED_ORIGINS=https://your-domain.com/ + +# ============================================================================= +# OIDC CONFIGURATION +# ============================================================================= + +# Enable OIDC authentication +PA_OIDC_ENABLED=false + +# OIDC provider domain (for discovery) +PA_OIDC_DOMAIN=https://your-oidc-provider.com + +# OIDC client credentials +PA_OIDC_CLIENT_ID=your-client-id +PA_OIDC_CLIENT_SECRET=your-client-secret + +# OIDC audience (optional) +PA_OIDC_AUDIENCE= + +# OIDC provider display name +PA_OIDC_PROVIDER_NAME=OIDC + +# Username field from OIDC user info to use as PlanarAlly username +# Options: preferred_username, name, email, sub, given_name, nickname +PA_OIDC_USERNAME_FIELD=preferred_username + +# Direct OIDC URL overrides (bypass discovery) +PA_OIDC_AUTHORIZE_URL=https://your-oidc-provider.com/auth +PA_OIDC_TOKEN_URL=https://your-oidc-provider.com/token +PA_OIDC_USERINFO_URL=https://your-oidc-provider.com/userinfo + +# ============================================================================= +# EXAMPLE CONFIGURATIONS +# ============================================================================= + +# Example 1: OIDC-only authentication +# PA_USERNAME_PASS=false +# PA_OIDC_ENABLED=true + +# Example 2: Both authentication methods +# PA_USERNAME_PASS=true +# PA_OIDC_ENABLED=true + +# OIDC scopes to request (space-separated) +# Standard scopes: openid, profile, email, address, phone +# Custom scopes: groups, roles, department (provider-specific) +PA_OIDC_SCOPE=openid profile email diff --git a/CHANGELOG.md b/CHANGELOG.md index dcd9014a6..cd9f0bd19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,21 @@ tech changes will usually be stripped from release notes for the public ## Unreleased +### Added + +- **OIDC (OpenID Connect) Authentication Support** + - Full OIDC authentication flow implementation with OAuth2 authorization code flow + - Support for OIDC discovery endpoints for automatic provider configuration + - Configurable OIDC provider settings including domain, client credentials, and scopes + - Option for direct URL configuration to bypass discovery for custom providers + - Automatic user creation and management with configurable username field mapping + - Secure state parameter validation to prevent CSRF attacks + - Server-side token exchange and user information retrieval + - Client-side OIDC login UI with provider-specific branding support + - Seamless integration with existing user management system + - [server] Fallback safety mechanism to prevent user lockout when OIDC is misconfigured + - [server] Comprehensive logging for troubleshooting OIDC authentication flows + - [server] Support for custom audience parameters for provider-specific requirements ## [2025.3] ### Added diff --git a/client/index.html b/client/index.html index be75bd25f..47ac88118 100644 --- a/client/index.html +++ b/client/index.html @@ -5,7 +5,13 @@ + + + + + + -