You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-21Lines changed: 30 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@
8
8
[![Nuxt][nuxt-src]][nuxt-href]
9
9
10
10
Welcome to __Nuxt OIDC Auth__, a Nuxt module focusing on native OIDC (OpenID Connect) based authentication for Nuxt with a high level of customizability and security for SSR applications.
11
-
This module doesn't use any external dependencies outside of the [unjs](https://unjs.io/) ecosystem except for token validation (the well known `jose` library for JWT interactions).
11
+
This module doesn't use any external dependencies outside of the [unjs](https://unjs.io/) ecosystem except for token validation (the well known and tested `jose` library for JWT interactions).
12
12
This module's session implementation is based on [nuxt-auth-utils](https://github.com/Atinux/nuxt-auth-utils).
@@ -28,15 +28,29 @@ This module's session implementation is based on [nuxt-auth-utils](https://githu
28
28
29
29
If you are looking for a module that supports local authentication (and more) provided by your Nuxt server, check out the nuxt-auth module from sidebase (powered by authjs and NextAuth) ➡️ [nuxt-auth](https://github.com/sidebase/nuxt-auth)
30
30
31
-
##Quick Setup
31
+
### Recent breaking changes
32
32
33
-
### 1. Add `nuxt-oidc-auth` dependency to your project
33
+
:warning: Since 0.16.0, the data from the providers userInfo endpoint is written into `userInfo` on the user object instead of `providerInfo`.
34
+
Please adjust your `nuxt.config.ts` and .env/environment files and configurations accordingly.
35
+
The `useOidcAuth` composable has introduced an alias from `providerInfo` to `userInfo`, but this will be removed in future versions.
36
+
37
+
## Installation
38
+
39
+
### Add `nuxt-oidc-auth` dependency to your project
40
+
41
+
With nuxi
34
42
35
43
```bash
36
-
npx nuxi@latest module add nuxt-oidc-auth
44
+
pnpm dlx nuxi@latest module add nuxt-oidc-auth
37
45
```
38
46
39
-
### 2. Add `nuxt-oidc-auth` to the `modules` section of `nuxt.config.ts`
47
+
or manually
48
+
49
+
```bash
50
+
pnpm add -D nuxt-oidc-auth
51
+
```
52
+
53
+
Add `nuxt-oidc-auth` to the `modules` section of `nuxt.config.ts`
Nuxt OIDC Auth uses three different secrets to encrypt the user session, the individual auth sessions and the persistent server side token store. You can set them using environment variables or in the `.env` file.
52
66
All of the secrets are auto generated if not set, but should be set manually in production. This is especially important for the session storage, as it won't be accessible anymore if the secret changes, for example, after a server restart.
53
67
54
68
If you need a reference how you could generate random secrets or keys, we created an example as a starting point: [Secrets generation example](https://stackblitz.com/edit/nuxt-oidc-auth-keygen?file=index.js)
55
69
56
-
- NUXT_OIDC_SESSION_SECRET (random string): This should be a at least 48 characters random string. It is used to encrypt the user session.
57
70
- NUXT_OIDC_TOKEN_KEY (random key): This needs to be a random cryptographic AES key in base64. Used to encrypt the server side token store. You can generate a key in JS with `await subtle.exportKey('raw', await subtle.generateKey({ name: 'AES-GCM', length: 256, }, true, ['encrypt', 'decrypt']))`. You just have to encode it to base64 afterwards.
71
+
- NUXT_OIDC_SESSION_SECRET (random string): This should be a at least 48 characters random string. It is used to encrypt the user session.
58
72
- NUXT_OIDC_AUTH_SESSION_SECRET (random string): This should be a at least 48 characters random string. It is used to encrypt the individual sessions during OAuth flows.
59
73
60
74
Add a `NUXT_OIDC_SESSION_SECRET` env variable with at least 48 characters in the `.env` file.
### 4. That's it! You can now add authentication to your Nuxt app ✨
83
+
✨ That's it! You can now add authentication with a predifined provider or a custom OIDC provider to your Nuxt app ✨
70
84
71
85
## Supported OpenID Connect Providers
72
86
@@ -114,7 +128,6 @@ Nuxt OIDC Auth automatically adds some API routes to interact with the current u
114
128
-`loggedIn`
115
129
-`user`
116
130
-`currentProvider`
117
-
-~~`configuredProviders`~~ - Deprecated
118
131
-`fetch`
119
132
-`refresh`
120
133
-`login`
@@ -181,10 +194,6 @@ The current user object.
181
194
182
195
The name of the currently logged in provider.
183
196
184
-
### ~~`configuredProviders` => (string[])~~ - Deprecated due to security concerns (exposes potentially sensitive information)
185
-
186
-
~~An array that contains the names of the configured providers.~~
187
-
188
197
### `fetch()` => (void)
189
198
190
199
Fetches/updates the current user session.
@@ -236,17 +245,17 @@ The `user` object provided by `useOidcAuth` contains the following properties:
236
245
| loggedInAt |`number`| Login timestamp in second precision |
237
246
| updatedAt |`number`| Refresh timestamp in second precision |
238
247
| expireAt |`number`| Session expiration timestamp in second precision. Either `loggedInAt` plus session max age or expiration of access token if available. |
239
-
|providerInfo|`Record<string, unknown>`| Additional information coming from the provider's userinfo endpoint |
248
+
|userInfo|`Record<string, unknown>`| Additional information coming from the provider's userinfo endpoint |
240
249
| userName |`string`| Coming either from the provider or from the configured mapped claim |
241
250
| claims |`Record<string, unknown>`| Additional optional claims from the id token, if `optionalClaims` setting is configured. |
242
251
| accessToken |`string`| Exposed access token, only existent when `exposeAccessToken` is configured. |
243
252
| idToken |`string`| Exposed access token, only existent when `exposeIdToken` is configured. |
244
253
245
-
You can define the type for your provider info by creating a type declaration file (for example, `auth.d.ts`) in your project:
254
+
You can extend the type for your provider info by creating a type declaration file (for example, `auth.d.ts`) in your project:
| tokenRequestType |`'form'`\|`'form-urlencoded'`\|`'json'` (optional) |`'form'`| Token request type |
421
430
| audience |`string` (optional) | - | Audience used for token validation (not included in requests by default, use additionalTokenParameters or additionalAuthParameters to add it) |
422
431
| requiredProperties |`string[]`| - | Required properties of the configuration that will be validated at runtime. |
423
-
|filterUserinfo|`string[]`(optional) | - | Filter userinfo response to only include these properties. |
432
+
|filterUserInfo|`string[]`(optional) | - | Filter userinfo response to only include these properties. |
| logoutRedirectParameterName |`string` (optional) | - | Query parameter name for logout redirect. Will be appended to the logoutUrl as a query parameter. |
426
435
| additionalAuthParameters |`Record<string, string>` (optional) | - | Additional parameters to be added to the authorization request. See [Provider specific configurations](#provider-specific-configurations) for possible parameters. |
427
436
| additionalTokenParameters |`Record<string, string>` (optional) | - | Additional parameters to be added to the token request. See [Provider specific configurations](#provider-specific-configurations) for possible parameters. |
428
-
| baseUrl |`string` (optional) | - | Base URL for the provider, used when to dynamically create authorizationUrl, tokenUrl, userinfoUrl and logoutUrl if possible. |
437
+
| baseUrl |`string` (optional) | - | Base URL for the provider, used when to dynamically create authorizationUrl, tokenUrl, userInfoUrl and logoutUrl if possible. |
429
438
| openIdConfiguration |`Record<string, unknown>` or `function (config) => Record<string, unknown>` (optional) | - | OpenID Configuration object or function promise that resolves to an OpenID Configuration object. |
| validateIdToken |`boolean` (optional) |`true`| Validate id token. |
@@ -498,7 +507,7 @@ Make sure to set the callback URL in your OAuth app settings as `<your-domain>/a
498
507
499
508
### Keycloak
500
509
501
-
For Keycloak you have to provide at least the `baseUrl`, `clientId` and `clientSecret` properties. The `baseUrl` is used to dynamically create the `authorizationUrl`, `tokenUrl` and `userinfoUrl`.
510
+
For Keycloak you have to provide at least the `baseUrl`, `clientId` and `clientSecret` properties. The `baseUrl` is used to dynamically create the `authorizationUrl`, `tokenUrl` and `userInfoUrl`.
502
511
Please include the realm you want to use in the `baseUrl` (e.g. `https://<keycloak-url>/realms/<realm>`).
503
512
Also remember to enable `Client authentication` to be able to get a client secret.
504
513
@@ -510,7 +519,7 @@ The following fields in the returned [user object](#user-object) can be configur
0 commit comments