|
| 1 | +<!-- SPDX-FileCopyrightText: 2021-2025 DINUM <[email protected]> --> |
| 2 | +<!-- SPDX-FileCopyrightText: 2024-2025 Université Grenoble Alpes --> |
| 3 | +<!-- SPDX-License-Identifier: CC-BY-4.0 --> |
| 4 | +<!-- SPDX-License-Identifier: Etalab-2.0 --> |
| 5 | + |
| 6 | +# Authentication |
| 7 | + |
| 8 | +Catalogi uses OpenID Connect (OIDC) for authentication, allowing you to connect to any OIDC-compliant identity provider. |
| 9 | + |
| 10 | +## How It Works |
| 11 | + |
| 12 | +Catalogi implements the standard OIDC Authorization Code Flow: |
| 13 | + |
| 14 | +1. User clicks login |
| 15 | +2. Application redirects to identity provider |
| 16 | +3. User authenticates with the provider |
| 17 | +4. Provider redirects back with authorization code |
| 18 | +5. Application exchanges code for tokens |
| 19 | +6. User is authenticated |
| 20 | + |
| 21 | +The implementation uses automatic OIDC discovery via `/.well-known/openid-configuration`, making it compatible with any standard OIDC provider. |
| 22 | + |
| 23 | +## Required Environment Variables |
| 24 | + |
| 25 | +To configure authentication, you need to set the following environment variables: |
| 26 | + |
| 27 | +| Variable | Description | Example | |
| 28 | +|----------|-------------|---------| |
| 29 | +| `OIDC_ISSUER_URI` | The OIDC provider's issuer URL (without `.well-known/openid-configuration`) | `https://auth.example.com/realms/my-realm` | |
| 30 | +| `OIDC_CLIENT_ID` | Your application's client ID registered with the provider | `catalogi` | |
| 31 | +| `OIDC_CLIENT_SECRET` | Your application's client secret | `secret-value-here` | |
| 32 | +| `OIDC_MANAGE_PROFILE_URL` | URL where users can manage their profile (optional) | `https://auth.example.com/realms/my-realm/account` | |
| 33 | +| `APP_URL` | Your Catalogi application URL (used for redirect URIs) | `http://localhost:3000` | |
| 34 | + |
| 35 | +## Redirect URIs to Configure |
| 36 | + |
| 37 | +When registering your application with the identity provider, you need to configure these redirect URIs: |
| 38 | + |
| 39 | +- **Login callback**: `${APP_URL}/api/auth/callback` |
| 40 | +- **Logout callback**: `${APP_URL}/api/auth/logout/callback` |
| 41 | + |
| 42 | +For example, if `APP_URL=http://localhost:3000`: |
| 43 | +- Login callback: `http://localhost:3000/api/auth/callback` |
| 44 | +- Logout callback: `http://localhost:3000/api/auth/logout/callback` |
| 45 | + |
| 46 | +## Required OIDC Scopes |
| 47 | + |
| 48 | +The application requests the following standard OIDC scopes: |
| 49 | +- `openid` - Required for OIDC |
| 50 | +- `email` - To get user email |
| 51 | +- `profile` - To get user profile information |
| 52 | + |
| 53 | +For AgentConnect/ProConnect, additional scopes are automatically added: |
| 54 | +- `given_name` |
| 55 | +- `usual_name` |
| 56 | + |
| 57 | +## Configuration Example |
| 58 | + |
| 59 | +### Keycloak |
| 60 | + |
| 61 | +Keycloak is an open-source identity and access management solution used as reference example. |
| 62 | + |
| 63 | +```bash |
| 64 | +OIDC_ISSUER_URI=http://localhost:8080/realms/catalogi |
| 65 | +OIDC_CLIENT_ID=catalogi |
| 66 | +OIDC_CLIENT_SECRET=your-client-secret |
| 67 | +OIDC_MANAGE_PROFILE_URL=http://localhost:8080/realms/catalogi/account |
| 68 | +APP_URL=http://localhost:3000 |
| 69 | +``` |
| 70 | + |
| 71 | +See [Setting up Keycloak](3.2-setup-a-keycloak.md) for detailed Keycloak setup instructions. |
| 72 | + |
| 73 | +## Other OIDC Providers |
| 74 | + |
| 75 | +Any OIDC-compliant provider should work (Keycloak, AgentConnect, ProConnect, Auth0, Okta, Google, Azure AD, etc.) as long as it: |
| 76 | +1. Provides a `/.well-known/openid-configuration` discovery endpoint |
| 77 | +2. Supports the Authorization Code flow |
| 78 | +3. Provides standard `openid`, `email`, and `profile` scopes |
| 79 | +4. Returns user information with at least `sub` and `email` claims |
| 80 | + |
| 81 | +Generic configuration: |
| 82 | +```bash |
| 83 | +OIDC_ISSUER_URI=https://your-provider.com |
| 84 | +OIDC_CLIENT_ID=your-client-id |
| 85 | +OIDC_CLIENT_SECRET=your-client-secret |
| 86 | +OIDC_MANAGE_PROFILE_URL=https://your-provider.com/account |
| 87 | +APP_URL=http://localhost:3000 |
| 88 | +``` |
| 89 | + |
| 90 | +## Security |
| 91 | + |
| 92 | +**Production requirements**: |
| 93 | +- Use HTTPS for `APP_URL` |
| 94 | +- Keep `OIDC_CLIENT_SECRET` secure |
| 95 | +- Sessions use secure HTTP-only cookies (24h expiry) |
| 96 | +- Tokens stored server-side only |
| 97 | + |
| 98 | +## Related Documentation |
| 99 | + |
| 100 | +- [Setting up Keycloak](3.2-setup-a-keycloak.md) - Detailed Keycloak setup guide |
| 101 | +- [Environment Variables and Customization](6-env-variables-and-customization.md) - All environment variables |
| 102 | +- [Deploying with Docker Compose](4-deploying-with-docker-compose.md) - Production deployment |
| 103 | +- [Deploying with Kubernetes](5-deploying-with-kubernetes.md) - Kubernetes deployment |
0 commit comments