|
| 1 | +import type { OAuthConfig, OAuthUserConfig } from "./oauth.js" |
| 2 | + |
| 3 | +/** |
| 4 | + * ## CIAM Provider |
| 5 | + * |
| 6 | + * This provider is designed to integrate with a CIAM (Customer Identity and Access Management) service. |
| 7 | + * It expects a set of endpoints to be configured for OAuth 2.0 authorization, token exchange, and user info retrieval. |
| 8 | + * |
| 9 | + * ### Configuration |
| 10 | + * |
| 11 | + * To use this provider, you must pass a configuration object with the following properties: |
| 12 | + * |
| 13 | + * - `clientId`: The client ID provided by your CIAM service. |
| 14 | + * - `clientSecret`: The client secret provided by your CIAM service. |
| 15 | + * - `authorizationUrl`: The authorization endpoint of your CIAM service. |
| 16 | + * - `tokenUrl`: The token endpoint of your CIAM service. |
| 17 | + * - `userinfoUrl`: The userinfo endpoint of your CIAM service. |
| 18 | + * - `issuer`: The issuer URL of your CIAM service. |
| 19 | + * - `jwksEndpoint`: The JWKS endpoint of your CIAM service. |
| 20 | + * |
| 21 | + * Additionally, you can override any of the default `OAuthConfig` properties. |
| 22 | + * |
| 23 | + * @param {Omit<OAuthUserConfig<Record<string, any>>, 'checks'> & { |
| 24 | + * authorizationUrl: string; |
| 25 | + * tokenUrl: string; |
| 26 | + * userinfoUrl: string; |
| 27 | + * issuer: string; |
| 28 | + * jwksEndpoint: string; |
| 29 | + * }} options |
| 30 | + * @returns {OAuthConfig<Record<string, any>>} |
| 31 | + */ |
| 32 | +export default function CiamProvider( |
| 33 | + options: Omit<OAuthUserConfig<Record<string, any>>, "checks"> & { |
| 34 | + authorizationUrl: string |
| 35 | + tokenUrl: string |
| 36 | + userinfoUrl: string |
| 37 | + issuer: string |
| 38 | + jwksEndpoint: string |
| 39 | + } |
| 40 | +): OAuthConfig<Record<string, any>> { |
| 41 | + return { |
| 42 | + id: "ciam", |
| 43 | + name: "CIAM", |
| 44 | + type: "oauth", |
| 45 | + checks: ["state"], |
| 46 | + authorization: { |
| 47 | + url: options.authorizationUrl, |
| 48 | + params: { |
| 49 | + scope: "openid profile", |
| 50 | + response_type: "code", |
| 51 | + }, |
| 52 | + }, |
| 53 | + token: options.tokenUrl, |
| 54 | + jwks_endpoint: options.jwksEndpoint, |
| 55 | + userinfo: options.userinfoUrl, |
| 56 | + profile(profile: any) { |
| 57 | + return { |
| 58 | + id: profile.sub, |
| 59 | + name: profile.sub, |
| 60 | + authorities: profile.authorities, |
| 61 | + } |
| 62 | + }, |
| 63 | + ...options, |
| 64 | + } |
| 65 | +} |
0 commit comments