|
| 1 | +/** |
| 2 | + * <div style={{display: "flex", justifyContent: "space-between", alignItems: "center"}}> |
| 3 | + * <span style={{fontSize: "1.35rem" }}> |
| 4 | + * Built-in sign in with <b>BankID Norway</b> integration. |
| 5 | + * </span> |
| 6 | + * <a href="https://bankid.no" style={{backgroundColor: "black", padding: "12px", borderRadius: "100%" }}> |
| 7 | + * <img style={{display: "block"}} src="https://authjs.dev/img/providers/bankid-no.svg" width="24"/> |
| 8 | + * </a> |
| 9 | + * </div> |
| 10 | + * |
| 11 | + * @module providers/bankid-no |
| 12 | + */ |
| 13 | +import type { OIDCConfig, OIDCUserConfig } from "./index.js" |
| 14 | + |
| 15 | +/** |
| 16 | + * @see [Core conepts - ID Token](https://confluence.bankidnorge.no/confluence/pdoidcl/technical-documentation/core-concepts/id-token) |
| 17 | + * @see [userinfo](https://confluence.bankidnorge.no/confluence/pdoidcl/technical-documentation/api/userinfo) |
| 18 | + */ |
| 19 | +export interface BankIDNorwayProfile { |
| 20 | + exp: number |
| 21 | + iat: number |
| 22 | + /** Epoc time */ |
| 23 | + auth_time: number |
| 24 | + jti: string |
| 25 | + iss: string |
| 26 | + /** Always client_id */ |
| 27 | + aud: string |
| 28 | + sub: string |
| 29 | + typ: "ID" |
| 30 | + /** Equals client_id */ |
| 31 | + azp: string |
| 32 | + session_state: string |
| 33 | + at_hash: string |
| 34 | + name: string |
| 35 | + given_name: string |
| 36 | + family_name: string |
| 37 | + birthdate: string |
| 38 | + updated_at: number |
| 39 | + /** |
| 40 | + * Uniform Resource Name for [IDP option](https://confluence.bankidnorge.no/confluence/pdoidcl/technical-documentation/core-concepts/identity-providers) being used, |
| 41 | + * including Level of Assurance (LoA). |
| 42 | + * @example |
| 43 | + * ``` |
| 44 | + * urn:bankid:bid;LOA=4 |
| 45 | + * ``` |
| 46 | + */ |
| 47 | + acr: string |
| 48 | + sid: string |
| 49 | + /** |
| 50 | + * Name of [IDP option](https://confluence.bankidnorge.no/confluence/pdoidcl/technical-documentation/core-concepts/identity-providers) being used to authenticate the end-user. |
| 51 | + * If the end-user is subject to authentication step-up, |
| 52 | + * note that this value may differ from any `amr` value specified |
| 53 | + * in the `login_hint` parameter of the [authorize](https://confluence.bankidnorge.no/confluence/pdoidcl/technical-documentation/api/authorize) endpoint. |
| 54 | + */ |
| 55 | + amr: "BID" | "BIM" | "BIS" |
| 56 | + /** Personal Identifier (PID) / Serial Number) from associated BankID certificate. */ |
| 57 | + bankid_altsub: string |
| 58 | + /** |
| 59 | + * In case of BID or BIM, the issuer of the end user certificate is returned. |
| 60 | + * @example |
| 61 | + * ``` |
| 62 | + * CN=BankID Bankenes ID-tjeneste Bank CA 2, |
| 63 | + * OU=988477052, |
| 64 | + * O=Bankenes ID-tjeneste AS,* |
| 65 | + * C=NO;OrginatorId=9775;OriginatorName=Gjensidige Bank RA 1 |
| 66 | + * ``` |
| 67 | + */ |
| 68 | + originator: string |
| 69 | + additionalCertInfo: { |
| 70 | + certValidFrom: number |
| 71 | + serialNumber: string |
| 72 | + keyAlgorithm: string |
| 73 | + keySize: string |
| 74 | + policyOid: string |
| 75 | + certQualified: boolean |
| 76 | + certValidTo: number |
| 77 | + versionNumber: string |
| 78 | + subjectName: string |
| 79 | + } |
| 80 | + /** Currently used as an input parameter for the [securityData](https://confluence.bankidnorge.no/confluence/pdoidcl/technical-documentation/api/securitydata) endpoint of the [Fraud Data](https://confluence.bankidnorge.no/confluence/pdoidcl/technical-documentation/advanced-topics/fraud-data) service */ |
| 81 | + tid: string |
| 82 | + /** Only returned from the `userinfo_endpoint` */ |
| 83 | + email?: string |
| 84 | + /** |
| 85 | + * [Norwegian National Identity Number (fødselsnummer)](https://www.skatteetaten.no/en/person/foreign/norwegian-identification-number/national-identity-number). It can be an alternative to `sub`. |
| 86 | + * Requires `nnin_altsub` scope at the [authorize](https://confluence.bankidnorge.no/confluence/pdoidcl/technical-documentation/api/authorize) endpoint. |
| 87 | + * @example |
| 88 | + * ``` |
| 89 | + * 181266***** |
| 90 | + * ``` |
| 91 | + */ |
| 92 | + nnin_altsub?: string |
| 93 | +} |
| 94 | + |
| 95 | +/** |
| 96 | + * ### Setup |
| 97 | + * |
| 98 | + * #### Callback URL |
| 99 | + * ``` |
| 100 | + * https://example.com/api/auth/callback/bankid-no |
| 101 | + * ``` |
| 102 | + * |
| 103 | + * #### Configuration |
| 104 | + * ```ts |
| 105 | + * import { Auth } from "@auth/core" |
| 106 | + * import BankIDNorge from "@auth/core/providers/bankid-no" |
| 107 | + * |
| 108 | + * const request = new Request(origin) |
| 109 | + * const response = await Auth(request, { |
| 110 | + * providers: [ |
| 111 | + * Auth0({ |
| 112 | + * clientId: AUTH_BANKID_NO_ID, |
| 113 | + * clientSecret: AUTH_BANKID_NO_SECRET, |
| 114 | + * }), |
| 115 | + * ], |
| 116 | + * }) |
| 117 | + * ``` |
| 118 | + * |
| 119 | + * ### Resources |
| 120 | + * |
| 121 | + * - [OpenID Connect Provider from BankID](https://confluence.bankidnorge.no/confluence/pdoidcl) |
| 122 | + * |
| 123 | + * ### Notes |
| 124 | + * |
| 125 | + * The BankID Norge provider comes with a [default configuration](https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/bankid-no.ts). To override the defaults for your use case, check out [customizing a built-in OAuth provider](https://authjs.dev/guides/configuring-oauth-providers). |
| 126 | + * |
| 127 | + * ## Help |
| 128 | + * |
| 129 | + * If you think you found a bug in the default configuration, you can [open an issue](https://authjs.dev/new/provider-issue). |
| 130 | + * |
| 131 | + * Auth.js strictly adheres to the specification and it cannot take responsibility for any deviation from |
| 132 | + * the spec by the provider. You can open an issue, but if the problem is non-compliance with the spec, |
| 133 | + * we might not pursue a resolution. You can ask for more help in [Discussions](https://authjs.dev/new/github-discussions). |
| 134 | + */ |
| 135 | +export default function BankIDNorway( |
| 136 | + config: OIDCUserConfig<BankIDNorwayProfile> |
| 137 | +): OIDCConfig<BankIDNorwayProfile> { |
| 138 | + return { |
| 139 | + id: "bankid-no", |
| 140 | + name: "BankID Norge", |
| 141 | + type: "oidc", |
| 142 | + issuer: "https://auth.bankid.no/auth/realms/prod", |
| 143 | + client: { |
| 144 | + token_endpoint_auth_method: "client_secret_post", |
| 145 | + userinfo_signed_response_alg: "RS256", |
| 146 | + }, |
| 147 | + idToken: false, |
| 148 | + authorization: { params: { ui_locales: "no", login_hint: "BIS" } }, |
| 149 | + profile(profile) { |
| 150 | + return { |
| 151 | + id: profile.sub, |
| 152 | + name: profile.name, |
| 153 | + email: profile.email ?? null, |
| 154 | + image: null, |
| 155 | + } |
| 156 | + }, |
| 157 | + checks: ["pkce", "state", "nonce"], |
| 158 | + style: { text: "#fff", bg: "#39134c" }, |
| 159 | + options: config, |
| 160 | + } |
| 161 | +} |
0 commit comments