|
| 1 | +/** |
| 2 | + * <div style={{display: "flex", justifyContent: "space-between", alignItems: "center"}}> |
| 3 | + * <span style={{fontSize: "1.35rem" }}> |
| 4 | + * Built-in sign in with <b>Descope</b> integration. |
| 5 | + * </span> |
| 6 | + * <a href="https://descope.com" style={{backgroundColor: "#000000", padding: "12px", borderRadius: "100%" }}> |
| 7 | + * <img style={{display: "block"}} src="https://authjs.dev/img/providers/descope.svg" width="24"/> |
| 8 | + * </a> |
| 9 | + * </div> |
| 10 | + * |
| 11 | + * @module providers/descope |
| 12 | + */ |
| 13 | + |
| 14 | +import type { OIDCConfig, OIDCUserConfig } from "./index.js" |
| 15 | + |
| 16 | +/** The returned user profile from Descope when using the profile callback. */ |
| 17 | +export interface DescopeProfile { |
| 18 | + /** The user Descope ID */ |
| 19 | + sub: string |
| 20 | + name: string |
| 21 | + email: string |
| 22 | + email_verified: boolean |
| 23 | + phone_number: string |
| 24 | + phone_number_verified: boolean |
| 25 | + picture: string |
| 26 | + /** Custom user's attributes */ |
| 27 | + [claim: string]: unknown |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * |
| 32 | + * ### Setup |
| 33 | + * |
| 34 | + * #### Callback URL |
| 35 | + * ``` |
| 36 | + * https://example.com/api/auth/callback/descope |
| 37 | + * ``` |
| 38 | + * |
| 39 | + * #### Configuration |
| 40 | + * |
| 41 | + * Import the provider and configure it in your **Auth.js** initialization file: |
| 42 | + * |
| 43 | + * ```ts title="pages/api/auth/[...nextauth].ts" |
| 44 | + * import NextAuth from "next-auth" |
| 45 | + * import DescopeProvider from "next-auth/providers/descope"; |
| 46 | + * |
| 47 | + * export default NextAuth({ |
| 48 | + * providers: [ |
| 49 | + * DescopeProvider({ |
| 50 | + * clientId: process.env.DESCOPE_ID, |
| 51 | + * clientSecret: process.env.DESCOPE_SECRET, |
| 52 | + * }), |
| 53 | + * ], |
| 54 | + * }) |
| 55 | + * ``` |
| 56 | + * |
| 57 | + * ### Configuring Descope |
| 58 | + * |
| 59 | + * Follow these steps: |
| 60 | + * |
| 61 | + * 1. Log into the [Descope console](https://app.descope.com) |
| 62 | + * 2. Follow the [OIDC instructions](https://docs.descope.com/customize/auth/oidc) |
| 63 | + * |
| 64 | + * Then, create a `.env.local` file in the project root add the following entries: |
| 65 | + * |
| 66 | + * Get the following from the Descope's console: |
| 67 | + * ``` |
| 68 | + * DESCOPE_ID="<Descope Issuer's last url segment>" # Descope's Issuer can be found in "Authentication Methods > SSO > Identity Provider" (Can also be taken from "Project > Project ID") |
| 69 | + * DESCOPE_SECRET="<Descope Access Key>" # Manage > Access Keys |
| 70 | + * ``` |
| 71 | + * |
| 72 | + * ### Resources |
| 73 | + * |
| 74 | + * - [Descope OIDC](https://docs.descope.com/customize/auth/oidc) |
| 75 | + * - [Descope Flows](https://docs.descope.com/customize/flows) |
| 76 | + * |
| 77 | + * ### Notes |
| 78 | + * |
| 79 | + * The Descope provider comes with a [default configuration](https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/descope.ts). To override the defaults for your use case, check out [customizing a built-in OAuth provider](https://authjs.dev/guides/providers/custom-provider#override-default-options). |
| 80 | + * |
| 81 | + * :::info |
| 82 | + * By default, Auth.js assumes that the Descope provider is based on the [OIDC](https://openid.net/specs/openid-connect-core-1_0.html) spec |
| 83 | + * ::: |
| 84 | + * |
| 85 | + * ## Help |
| 86 | + * |
| 87 | + * If you think you found a bug in the default configuration, you can [open an issue](https://authjs.dev/new/provider-issue). |
| 88 | + * |
| 89 | + * Auth.js strictly adheres to the specification and it cannot take responsibility for any deviation from |
| 90 | + * the spec by the provider. You can open an issue, but if the problem is non-compliance with the spec, |
| 91 | + * we might not pursue a resolution. You can ask for more help in [Discussions](https://authjs.dev/new/github-discussions). |
| 92 | + */ |
| 93 | +export default function Descope( |
| 94 | + config: OIDCUserConfig<DescopeProfile> |
| 95 | +): OIDCConfig<DescopeProfile> { |
| 96 | + return { |
| 97 | + id: "descope", |
| 98 | + name: "Descope", |
| 99 | + type: "oidc", |
| 100 | + clientId: `https://api.descope.com/${config.clientId}`, |
| 101 | + style: { |
| 102 | + logo: "/descope.svg", |
| 103 | + logoDark: "/descope.svg", |
| 104 | + bg: "#1C1C23", |
| 105 | + text: "#ffffff", |
| 106 | + bgDark: "#1C1C23", |
| 107 | + textDark: "#ffffff", |
| 108 | + }, |
| 109 | + options: config, |
| 110 | + } |
| 111 | +} |
0 commit comments