|
| 1 | +import type { Profile } from "../types.js" |
| 2 | +import type { |
| 3 | + CommonProviderOptions, |
| 4 | + OIDCConfig, |
| 5 | + OIDCUserConfig, |
| 6 | +} from "./index.js" |
| 7 | +/** |
| 8 | + * <div class="provider" style={{ display: "flex", justifyContent: "space-between", color: "#fff" }}> |
| 9 | + * <span>Built-in <b>a12n-server</b> integration.</span> |
| 10 | + * <a href="https://github.com/.org"> |
| 11 | + * <img style={{display: "block"}} src="https://authjs.dev/img/providers/a12n-server.svg" height="48" width="48"/> |
| 12 | + * </a> |
| 13 | + * </div> |
| 14 | + * |
| 15 | + * @module providers/a12n-server |
| 16 | + */ |
| 17 | + |
| 18 | +export interface A12nServerProfile |
| 19 | + extends Record<keyof CommonProviderOptions, string> { |
| 20 | + id: string |
| 21 | + /* The provider name used on the default sign-in page's sign-in button. */ |
| 22 | + name: string |
| 23 | + token_type?: "bearer" | "refresh_token" |
| 24 | + type: "oidc" |
| 25 | +} |
| 26 | + |
| 27 | +/** |
| 28 | + * Add a12n-server login to your page. |
| 29 | + * |
| 30 | + * ### Setup |
| 31 | + * |
| 32 | + * In `.env` create the following entries: |
| 33 | + * {@link https://github.com/curveball/next-a12n?tab=readme-ov-file#environment-variables} |
| 34 | + * ``` |
| 35 | + * AUTH_A12N_ISSUER= |
| 36 | + * AUTH_A12N_ID= |
| 37 | + * AUTH_A12N_SECRET= |
| 38 | + * ``` |
| 39 | + * |
| 40 | + * #### Callback URL |
| 41 | + * ``` |
| 42 | + * https://your-site-or-backend.com/api/auth/callback/a12n-server |
| 43 | + * ``` |
| 44 | + * |
| 45 | + * #### Configuration |
| 46 | + *```ts |
| 47 | + * import { Auth } from "@auth/core" |
| 48 | + * import a12n from "@auth/core/providers/a12n-server" |
| 49 | + * |
| 50 | + * const request = new Request(origin) |
| 51 | + * const response = await Auth(request, { |
| 52 | + * providers: [ |
| 53 | + * a12n({ |
| 54 | + * clientId: process.env.AUTH_A12N_ID, |
| 55 | + * clientSecret: process.env.AUTH_A12N_SECRET |
| 56 | + * }), |
| 57 | + * ] |
| 58 | + * }) |
| 59 | + * ``` |
| 60 | + * |
| 61 | + * ### Resources |
| 62 | + * |
| 63 | + * - a12n-server [Overview](https://github.com/curveball/a12n-server/blob/main/docs/getting-started.md) |
| 64 | + * [Set up a12n-server](https://github.com/curveball/next-a12n/blob/main/README.md#setting-up-a12n-server) |
| 65 | + * - [How to add a new client to a12n-server](https://github.com/curveball/next-a12n/tree/main?tab=readme-ov-file#register-a-new-client-side-web-app-on-curveballa12n-server) |
| 66 | + * - [How to retrieve the user's information from your a12n-server](https://github.com/curveball/a12n-server/blob/main/docs/user-api.md) |
| 67 | + * - [Learn more about OAuth](https://authjs.dev/concepts/oauth) |
| 68 | + * |
| 69 | + * ### Notes |
| 70 | + * |
| 71 | + * Grant type: Authorization Code |
| 72 | + * |
| 73 | + * By default, Auth.js assumes that the a12n-server Oauth2 provider is |
| 74 | + * based on the [OAuth 2](https://www.rfc-editor.org/rfc/rfc6749.html) specification. |
| 75 | + * |
| 76 | + * :::tip |
| 77 | + * |
| 78 | + * ## Help |
| 79 | + * |
| 80 | + * If you think you found a bug in the default configuration, you can [open an issue](https://authjs.dev/new/provider-issue). |
| 81 | + * |
| 82 | + * Auth.js strictly adheres to the specification and it cannot take responsibility for any deviation from |
| 83 | + * the spec by the provider. You can open an issue, but if the problem is non-compliance with the spec, |
| 84 | + * we might not pursue a resolution. You can ask for more help in [Discussions](https://authjs.dev/new/github-discussions). |
| 85 | + */ |
| 86 | +export interface A12nServerUserProfile |
| 87 | + extends Record<keyof Profile, Profile[keyof Profile]> { |
| 88 | + sub: string |
| 89 | + email?: string |
| 90 | + email_verified?: boolean |
| 91 | + name: string |
| 92 | + website?: string |
| 93 | + zoneinfo?: string |
| 94 | + given_name?: string |
| 95 | + family_name?: string |
| 96 | + preferred_username?: string |
| 97 | + phone_number?: string |
| 98 | + phone_number_verified?: boolean |
| 99 | + locale?: string |
| 100 | + updated_at: number |
| 101 | + picture?: string |
| 102 | + address?: string |
| 103 | + birthdate?: string |
| 104 | +} |
| 105 | + |
| 106 | +export default function a12n( |
| 107 | + config: OIDCConfig<A12nServerProfile> |
| 108 | +): OIDCUserConfig<A12nServerUserProfile> { |
| 109 | + return { |
| 110 | + id: "a12n-server", |
| 111 | + name: "a12n-server", |
| 112 | + issuer: config.issuer, |
| 113 | + clientId: config.clientId, |
| 114 | + clientSecret: config.clientSecret, |
| 115 | + checks: ["pkce", "state", "nonce"], |
| 116 | + profile(profile) { |
| 117 | + return { |
| 118 | + ...profile, |
| 119 | + updated_at: Date.now(), |
| 120 | + } satisfies A12nServerUserProfile |
| 121 | + }, |
| 122 | + } |
| 123 | +} |
0 commit comments