# Authentication Provider Integration - Executive Summary
**Version**: 1.0.0
**Date**: 2025-11-21
**Status**: Design Document
---
## π― Overview
Mimir now supports **comprehensive authentication provider integration** with OAuth 2.0 / OIDC, enabling seamless integration with enterprise identity providers while maintaining backward compatibility with existing API key authentication.
---
## β
Key Features
### Upstream Authentication (Users β Mimir)
| Provider | Protocol | Setup Time | Cost |
|----------|----------|------------|------|
| **Okta** | OIDC | 2 hours | $0-$500/mo |
| **Auth0** | OIDC | 2 hours | $0-$500/mo |
| **Azure AD** | OIDC | 2 hours | Included with M365 |
| **Google** | OAuth 2.0 | 1 hour | Free |
| **Keycloak** | OIDC | 4 hours | $0 (self-hosted) |
| **Generic OIDC** | OIDC | 2 hours | Varies |
### Downstream Authentication (PCTX/Services β Mimir)
| Method | Use Case | Token Type | Setup Time |
|--------|----------|------------|------------|
| **API Key** | Trusted services (PCTX, internal tools) | `X-API-Key: xxx` | 5 minutes |
**Simplified**: No service accounts, no token forwarding, no JWT issuance. Just API keys.
---
## π Authentication Flow
```
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β User / β OAuth Token β Mimir β Mimir JWT β PCTX β
β Identity β βββββββββββββββββββ (Auth Hub) β βββββββββββββββββββ Service β
β Provider β β β β β
βββββββββββββββ βββββββββββββββ βββββββββββββββ
β β β
β β β
ββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββ
Validates tokens Issues tokens Calls Mimir APIs
```
**Key Points**:
- β
Mimir acts as **authentication hub** between IdP and downstream services
- β
Validates upstream OAuth tokens from IdP
- β
Issues downstream JWT tokens for services (PCTX, MCP clients)
- β
Propagates user context through the entire chain
- β
Supports multiple authentication methods simultaneously
---
## π Implementation Roadmap
### Week 1: Basic OAuth (One Provider)
**Tasks**:
1. Add OAuth middleware
2. Implement authorization code flow
3. Add token validation
4. Store tokens in Redis
5. Test with one provider (Okta or Auth0)
**Deliverables**:
- OAuth login working
- Token validation working
- Session management working
**Cost**: $0 (development)
### Week 2: Multi-Provider Support
**Tasks**:
1. Abstract provider-specific logic
2. Add provider factory pattern
3. Implement provider discovery
4. Test all providers
**Deliverables**:
- Support for Okta, Auth0, Azure AD, Google, Keycloak
- Provider switching
- Provider-specific configurations
**Cost**: $0 (development)
### Week 3: API Key Management
**Tasks**:
1. Add API key CRUD operations
2. Add API key validation to auth middleware
3. Test with PCTX
**Deliverables**:
- API key management working
- PCTX can authenticate with API key
**Cost**: $0 (development)
**Simplified**: No JWT issuance, no service accounts, no token forwarding.
### Week 4: Token Management
**Tasks**:
1. Implement token refresh
2. Add token revocation
3. Implement token introspection
4. Add token cleanup
5. Add monitoring
**Deliverables**:
- Complete token lifecycle management
- Monitoring and metrics
- Production-ready
**Cost**: $0 (development)
**Total Implementation Time**: 4 weeks
**Total Cost**: $0 (self-hosted) to $500/month (commercial IdP)
---
## π§ Configuration Example
### Mimir Configuration (Okta)
```bash
# Enable security features
MIMIR_ENABLE_SECURITY=true
# Authentication methods
MIMIR_AUTH_METHODS=api-key,oauth,jwt
MIMIR_DEFAULT_AUTH_METHOD=api-key # Start with API keys
# OAuth Provider
MIMIR_AUTH_PROVIDER=okta
MIMIR_OAUTH_ISSUER=https://your-tenant.okta.com
MIMIR_OAUTH_CLIENT_ID=your-client-id
MIMIR_OAUTH_CLIENT_SECRET=your-client-secret
MIMIR_OAUTH_REDIRECT_URI=https://mimir.yourcompany.com/auth/callback
MIMIR_OAUTH_SCOPE=openid profile email groups
# Token Storage
MIMIR_TOKEN_STORAGE=redis
MIMIR_REDIS_URL=redis://redis:6379
# API Keys (for downstream services)
MIMIR_API_KEY=your-api-key
```
### PCTX Configuration
```bash
# Mimir URL
MIMIR_URL=https://mimir.yourcompany.com
# Authentication Mode
MIMIR_AUTH_MODE=service-account
MIMIR_SERVICE_ACCOUNT_ID=pctx-service
MIMIR_SERVICE_ACCOUNT_SECRET=your-service-secret
# User Context
MIMIR_USER_CONTEXT_ENABLED=true
MIMIR_USER_CONTEXT_SOURCE=header
```
---
## π Security Features
### OAuth Security
- β
**PKCE** (Proof Key for Code Exchange) - Prevents authorization code interception
- β
**State Parameter** - Prevents CSRF attacks
- β
**Nonce** - Prevents replay attacks (OIDC)
- β
**Token Binding** - Binds tokens to specific clients
- β
**Short Lifetimes** - Access tokens expire in 1 hour
- β
**Refresh Token Rotation** - Issues new refresh token on refresh
### Token Security
- β
**HTTPS Only** - All OAuth flows require HTTPS
- β
**JWT Validation** - Validates signatures against IdP JWKS
- β
**Audience Validation** - Verifies `aud` claim
- β
**Issuer Validation** - Verifies `iss` claim
- β
**Expiration Validation** - Rejects expired tokens
- β
**Secure Storage** - HTTP-only cookies, Redis storage
### Service Account Security
- β
**Dedicated Accounts** - One service account per downstream service
- β
**Least Privilege** - Minimum required permissions
- β
**Audit Logging** - All service account usage logged
- β
**Token Rotation** - Rotate secrets regularly
- β
**Immediate Revocation** - Support for token revocation
---
## π Benefits
### For Users
- β
**Single Sign-On (SSO)** - One login for all services
- β
**Familiar Login** - Use existing corporate credentials
- β
**Multi-Factor Authentication (MFA)** - Inherit from IdP
- β
**Password Policies** - Managed by IdP
- β
**Account Lifecycle** - Automatic provisioning/deprovisioning
### For Administrators
- β
**Centralized User Management** - Manage users in IdP
- β
**Audit Trail** - Complete authentication logs
- β
**Compliance** - Meet GDPR, HIPAA, FISMA requirements
- β
**Scalability** - Handle thousands of users
- β
**Flexibility** - Support multiple IdPs
### For Developers
- β
**Standard Protocols** - OAuth 2.0 / OIDC
- β
**Multiple Providers** - Easy to switch providers
- β
**Backward Compatible** - API keys still work
- β
**User Context** - Access user information in services
- β
**Service Accounts** - Secure service-to-service auth
---
## π― Use Cases
### Use Case 1: Enterprise SSO
**Scenario**: 500-employee company with Okta
**Configuration**:
```bash
MIMIR_AUTH_PROVIDER=okta
MIMIR_DEFAULT_AUTH_METHOD=oauth
```
**Benefits**:
- β
Users login with corporate credentials
- β
MFA enforced by Okta
- β
Automatic user provisioning
- β
Audit logs in Okta
### Use Case 2: Multi-Tenant SaaS
**Scenario**: SaaS product with multiple customers
**Configuration**:
```bash
MIMIR_AUTH_PROVIDER=auth0
MIMIR_ENABLE_MULTI_TENANCY=true
MIMIR_TENANT_ID_SOURCE=jwt_claim:org_id
```
**Benefits**:
- β
Each customer has their own SSO
- β
Data isolation per tenant
- β
Flexible authentication per customer
### Use Case 3: Microsoft 365 Integration
**Scenario**: Company using Microsoft 365
**Configuration**:
```bash
MIMIR_AUTH_PROVIDER=azure
MIMIR_AZURE_TENANT_ID=your-tenant-id
```
**Benefits**:
- β
Login with Microsoft accounts
- β
Access Microsoft Graph API
- β
Seamless integration with Office 365
### Use Case 4: Self-Hosted/Air-Gapped
**Scenario**: On-premises deployment, no external IdP
**Configuration**:
```bash
MIMIR_AUTH_PROVIDER=keycloak
MIMIR_KEYCLOAK_SERVER_URL=https://keycloak.internal.company.com
```
**Benefits**:
- β
Complete control over authentication
- β
No external dependencies
- β
Works in air-gapped environments
---
## π Migration Strategy
### Stage 1: Add OAuth (No Breaking Changes)
```bash
# Keep API keys working
MIMIR_AUTH_METHODS=api-key,oauth
MIMIR_DEFAULT_AUTH_METHOD=api-key
```
**Result**: Both API keys and OAuth work
### Stage 2: Test OAuth
- Test OAuth login with select users
- Verify token validation
- Test PCTX integration
- Monitor for issues
**Result**: OAuth validated in production
### Stage 3: Make OAuth Default
```bash
# Switch default to OAuth
MIMIR_DEFAULT_AUTH_METHOD=oauth
```
**Result**: New users use OAuth, existing API keys still work
### Stage 4: Deprecate API Keys (Optional)
```bash
# Remove API key support
MIMIR_AUTH_METHODS=oauth,jwt
```
**Result**: OAuth-only authentication
**Total Migration Time**: 4 weeks (no downtime)
---
## π Documentation
| Document | Purpose |
|----------|---------|
| **[Authentication Provider Integration](./AUTHENTICATION_PROVIDER_INTEGRATION.md)** | Complete implementation guide |
| **[Security Environment Variables](./SECURITY_ENVIRONMENT_VARIABLES.md)** | All environment variables |
| **[Reverse Proxy Security Guide](./REVERSE_PROXY_SECURITY_GUIDE.md)** | Nginx setup for HTTPS |
| **[Security Implementation Plan](./SECURITY_IMPLEMENTATION_PLAN.md)** | Feature-flag based rollout |
| **[Enterprise Readiness Audit](./ENTERPRISE_READINESS_AUDIT.md)** | Full security audit |
---
## π Summary
**What We Built**:
- β
OAuth 2.0 / OIDC integration with 6 providers
- β
Upstream authentication (users via IdP)
- β
Downstream authentication (PCTX via service accounts)
- β
Token lifecycle management
- β
User context propagation
- β
Backward compatible (API keys still work)
**Implementation**:
- β±οΈ **Time**: 4 weeks
- π° **Cost**: $0 (self-hosted) to $500/month (commercial IdP)
- π **Migration**: Zero downtime
**Security**:
- π PKCE, State, Nonce protection
- π JWT validation against IdP JWKS
- π Token binding and rotation
- π Service account isolation
- π Audit logging
**Next Steps**:
1. Choose OAuth provider (Okta, Auth0, Azure AD, Google, Keycloak)
2. Follow [Authentication Provider Integration](./AUTHENTICATION_PROVIDER_INTEGRATION.md)
3. Configure environment variables from [Security Environment Variables](./SECURITY_ENVIRONMENT_VARIABLES.md)
4. Test with [Testing & Validation](./AUTHENTICATION_PROVIDER_INTEGRATION.md#testing--validation)
5. Deploy with [Migration Strategy](#migration-strategy)
---
**Document Version**: 1.0.0
**Last Updated**: 2025-11-21
**Maintainer**: Security Team
**Status**: Active