Overview
OIDC authentication provides:- Single Sign-On: Users authenticate through your identity provider
- Automatic Account Linking: Matches users by email and links OIDC identity
- Profile Sync: Name and avatar are synchronized from the provider
- PKCE Support: Works with public clients (no client secret required)
- Flexible Configuration: Configure via environment variables or admin UI
Configuration Methods
- Environment Variables
- Admin Panel
Configure OIDC using environment variables in your
.env file:.env
When OIDC settings are configured via environment variables, they cannot be changed through the admin UI.
Required Configuration
| Parameter | Description | Required |
|---|---|---|
OIDC_ENABLED | Enable/disable OIDC authentication | Yes |
OIDC_ISSUER_URL | Your identity provider’s issuer URL | Yes |
OIDC_CLIENT_ID | OAuth 2.0 client ID | Yes |
OIDC_CLIENT_SECRET | OAuth 2.0 client secret | No* |
OIDC_PROVIDER_NAME | Display name for the provider | No |
DISABLE_INTERNAL_AUTH | Hide local login form | No |
APP_URL | Base URL for callbacks | Yes |
*Client secret is optional when using PKCE (Proof Key for Code Exchange) for public clients like mobile apps.
Callback URL
Configure your identity provider with this callback URL:- Development:
http://localhost:3000/api/auth/oidc/callback - Production:
https://anchor.yourdomain.com/api/auth/oidc/callback
Provider-Specific Setup
- Pocket ID
- Keycloak
- Auth0
- Google
Authentication Flow
User initiates OIDC login
The user clicks “Sign in with [Provider]” button, which redirects to:Optional
redirect parameter specifies where to redirect after successful login.Authorization request
Anchor generates:
- CSRF protection state token
- PKCE code challenge (if no client secret)
- Stores state in memory with redirect URL
Token exchange
Anchor:
- Validates the state parameter
- Exchanges authorization code for tokens
- Fetches user information from provider
- Extracts claims (email, name, subject, picture)
User provisioning
Anchor finds or creates the user:
- Existing User by Subject
- Existing User by Email
- New User
User with matching
oidcSubject is found and updated with latest profile info.Redirect to frontend
User is redirected to:The frontend exchanges the one-time code for actual tokens.
Mobile Authentication
For mobile apps, use the direct token exchange endpoint:Mobile Login
Account Linking Behavior
Automatic Linking
Automatic Linking
When a user logs in with OIDC and an account with the same email exists:
- If the account has no OIDC subject → Link is created automatically
- If the account has a different OIDC subject → Error (email already linked)
- User can now authenticate with either local credentials or OIDC
Password Management
Password Management
Users created via OIDC have no password:
- Cannot use local authentication endpoint
- Password change endpoint returns error
- Must authenticate through OIDC provider
- Linked accounts retain their password capability
Profile Synchronization
Profile Synchronization
On each OIDC login:
- Display name is updated from provider
- Profile picture is downloaded if provided
- Old OIDC-downloaded avatars are replaced
- Manually uploaded avatars are preserved
Disabling Local Authentication
For SSO-only deployments, disable the local login form:.env
Required OIDC Claims
Anchor requires these standard OIDC claims:| Claim | Source | Usage |
|---|---|---|
sub | ID token or userinfo | Unique user identifier |
email | ID token or userinfo | User’s email address |
name | ID token or userinfo | Display name (fallback to username or email) |
picture | ID token or userinfo | Profile avatar URL (optional) |
Checking OIDC Configuration
Get current OIDC settings:Check Config
Troubleshooting
Invalid or expired state
Invalid or expired state
Cause: State token expired (60 seconds) or invalidSolution: Try logging in again. Ensure system clocks are synchronized.
Invalid or expired login code
Invalid or expired login code
Cause: Exchange code expired (30 seconds) or already usedSolution: Exchange codes are single-use. Return to login page and try again.
Email already linked to different account
Email already linked to different account
Cause: Email exists with different OIDC subjectSolution: Use the original OIDC provider or contact administrator to unlink.
OIDC provider did not return required claims
OIDC provider did not return required claims
Cause: Provider missing
email or sub claimSolution: Check identity provider configuration. Ensure email scope is requested.Implementation Reference
The OIDC implementation can be found in:- Controller:
server/src/auth/oidc/oidc.controller.ts - Service:
server/src/auth/oidc/oidc.service.ts - Config:
server/src/auth/oidc/oidc-config.service.ts - User linking:
server/src/auth/oidc/oidc-user.service.ts
Next Steps
User Management
Configure registration modes for OIDC users
Local Auth
Configure local authentication alongside OIDC