Skip to content

Commit 1e18b15

Browse files
committed
docs(provider): 📝 Added AWS Cognito; Updated providers section
1 parent 3da9e5d commit 1e18b15

File tree

15 files changed

+264
-201
lines changed

15 files changed

+264
-201
lines changed

README.md

Lines changed: 103 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ If you are looking for a module that supports local authentication (and more) pr
3030

3131
### Recent breaking changes
3232

33-
:warning: Since 0.16.0, the data from the providers userInfo endpoint is written into `userInfo` on the user object instead of `providerInfo`.
33+
⚠️ Since 0.16.0, the data from the providers userInfo endpoint is written into `userInfo` on the user object instead of `providerInfo`.
3434
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.
35+
If you are using the user object from the `useOidcAuth` composable change the access to `providerInfo` to `userInfo`.
3636

3737
## Installation
3838

@@ -332,7 +332,7 @@ The following hooks are available to extend the default behavior of the OIDC mod
332332
- `clear` (Called before a user session is cleared)
333333
- `refresh` (Called before a user session is refreshed)
334334

335-
:warning: Remember to also update the refresh hook if you modify the session, as claims and other fields would otherwise be wiped.
335+
⚠️ Remember to also update the refresh hook if you modify the session, as claims and other fields would otherwise be wiped.
336336

337337
#### Example
338338

@@ -435,7 +435,7 @@ export default defineNuxtConfig({
435435
| additionalAuthParameters | `Record<string, string>` (optional) | - | Additional parameters to be added to the authorization request. See [Provider specific configurations](#provider-specific-configurations) for possible parameters. |
436436
| additionalTokenParameters | `Record<string, string>` (optional) | - | Additional parameters to be added to the token request. See [Provider specific configurations](#provider-specific-configurations) for possible parameters. |
437437
| baseUrl | `string` (optional) | - | Base URL for the provider, used when to dynamically create authorizationUrl, tokenUrl, userInfoUrl and logoutUrl if possible. |
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. |
438+
| openIdConfiguration | `string` or `Record<string, unknown>` or `function (config) => Record<string, unknown>` (optional) | - | OpenID Configuration url, object or function promise that resolves to an OpenID Configuration object. |
439439
| validateAccessToken | `boolean` (optional) | `true` | Validate access token. |
440440
| validateIdToken | `boolean` (optional) | `true` | Validate id token. |
441441
| encodeRedirectUri | `boolean` (optional) | `false` | Encode redirect uri query parameter in authorization request. Only for compatibility with services that don't implement proper parsing of query parameters. |
@@ -476,29 +476,95 @@ The following options are available on every provider as overrides for the globa
476476

477477
Some providers have specific additional fields that can be used to extend the authorization or token request. These fields are available via. `additionalAuthParameters` or `additionalTokenParameters` in the provider configuration.
478478

479-
:warning: Tokens will only be validated if the `clientId` or the optional `audience` field is part of the access_tokens audiences. Even if `validateAccessToken` or `validateIdToken` is set, if the audience doesn't match, the token should not and will not be validated.
479+
⚠️ Tokens will only be validated if the `clientId` or the optional `audience` field is part of the access_tokens audiences. Even if `validateAccessToken` or `validateIdToken` is set, if the audience doesn't match, the token should not and will not be validated.
480+
481+
The `redirectUri` property is always required.
480482

481483
### Auth0
482484

483-
additionalAuth/TokenParameters:
485+
**Provider support:**
486+
487+
&nbsp; PKCE<br>
488+
&nbsp; Nonce<br>
489+
&nbsp; State<br>
490+
&nbsp; Access Token validation<br>
491+
&nbsp; ID Token validation<br>
492+
493+
**Instructions**
494+
495+
Additional parameters to be used in additionalAuthParameters,
496+
additionalTokenParameters or additionalLogoutParameters:
484497

485498
| Option | Type | Default | Description |
486499
|---|---|---|---|
487-
| connection | `string` | - | Optional. Specifies the connection. |
488-
| organization | `string` | - | Optional. Specifies the organization. |
489-
| invitation | `string` | - | Optional. Specifies the invitation. |
490-
| loginHint | `string` | - | Optional. Specifies the login hint. |
500+
| connection | `string` | - | Optional. Forces the user to sign in with a specific connection. For example, you can pass a value of github to send the user directly to GitHub to log in with their GitHub account. When not specified, the user sees the Auth0 Lock screen with all configured connections. You can see a list of your configured connections on the Connections tab of your application. |
501+
| organization | `string` | - | Optional. ID of the organization to use when authenticating a user. When not provided, if your application is configured to Display Organization Prompt, the user will be able to enter the organization name when authenticating. |
502+
| invitation | `string` | - | Optional. Ticket ID of the organization invitation. When inviting a member to an Organization, your application should handle invitation acceptance by forwarding the invitation and organization key-value pairs when the user accepts the invitation. |
503+
| loginHint | `string` | - | Optional. Populates the username/email field for the login or signup page when redirecting to Auth0. Supported by the Universal Login experience. |
504+
| audience | `string` | - | Optional. The unique identifier of the API your web app wants to access. |
505+
506+
Depending on the settings of your apps `Credentials` tab, set `authenticationScheme` to `body` for 'Client Secret (Post)', set to `header` for 'Client Secret (Basic)', set to `''` for 'None'
507+
508+
### AWS Cognito
509+
510+
**Provider support:**
491511

492-
- Depending on the settings of your apps `Credentials` tab, set `authenticationScheme` to `body` for 'Client Secret (Post)', set to `header` for 'Client Secret (Basic)', set to `''` for 'None'
512+
&nbsp; PKCE<br>
513+
&nbsp; Nonce<br>
514+
&nbsp; State<br>
515+
&nbsp; Access Token validation<br>
516+
&nbsp; ID Token validation<br>
517+
518+
AWS Congito doesn't correctly implement the OAuth 2 standard and doesn't provide a `aud` field for the audience. Therefore it is not possible to verify the access or id token.
519+
520+
**Instructions**
521+
522+
For AWS Cognito you have to provide at least the `baseUrl`, `clientId`, `clientSecret` and `logoutRedirectUri` properties. The `baseUrl` is used to dynamically create the `authorizationUrl`, `tokenUrl`, `logoutUrl` and `userInfoUrl`.
523+
The only supported OAuth grant type is `Authorization code grant`.
524+
The final url should look something like this `https://cognito-idp.eu-north-1.amazonaws.com/eu-north-1_SOMEID/.well-known/openid-configuration`.
525+
You will also encounter an error, if you have not correctly registered the `redirectUri` under "Allowed callback URLs" or the `logoutRedirectUri` under "Allowed sign-out URLs".
526+
If you need additional scopes, specify them in the `scope` property in you nuxt config like `scope: ['openid', 'email', 'profile'],`.
493527

494528
### Entra ID/Microsoft
495529

530+
**Provider support:**
531+
532+
&nbsp; PKCE<br>
533+
&nbsp; Nonce<br>
534+
&nbsp; State<br>
535+
⚠️&nbsp; Access Token validation (Supported, but disabled as only possible for custom audience tokens)<br>
536+
&nbsp; ID Token validation<br>
537+
538+
**Instructions**
539+
540+
Additional parameters to be used in additionalAuthParameters,
541+
additionalTokenParameters or additionalLogoutParameters:
542+
543+
| Option | Type | Default | Description |
544+
|---|---|---|---|
545+
| resource | `string` | - | Optional. The resource identifier for the requested resource. |
546+
| audience | `string` | - | Optional. The audience for the token, typically the client ID. |
547+
| prompt | `string` | - | Optional. Indicates the type of user interaction that is required. Valid values are login, none, consent, and select_account. |
548+
| loginHint | `string` | - | Optional. You can use this parameter to pre-fill the username and email address field of the sign-in page for the user. Apps can use this parameter during reauthentication, after already extracting the login_hint optional claim from an earlier sign-in. |
549+
| logoutHint | `string` | - | Optional. Enables sign-out to occur without prompting the user to select an account. To use logout_hint, enable the login_hint optional claim in your client application and use the value of the login_hint optional claim as the logout_hint parameter. |
550+
| domainHint | `string` | - | Optional. If included, the app skips the email-based discovery process that user goes through on the sign-in page, leading to a slightly more streamlined user experience. |
551+
496552
If you want to validate access tokens from Microsoft Entra ID (previously Azure AD), you need to make sure that the scope includes your own API. You have to register an API first and expose some scopes to your App Registration that you want to request. If you only have GraphAPI entries like `openid`, `mail` GraphAPI specific ones in your scope, the returned access token cannot and should not be verified. If the scope is set correctly, you can set `validateAccessToken` option to `true`.
497553

498-
If you use this module with Entra ID for Customers make sure you have set the `audience` config field to your application id, otherwise it will not be possible to get a valid OpenID Connect well-known configuration and thereby verify the JWT token.
554+
If you use this module with Entra External ID (previously Entra ID for Customers) make sure you have set the `audience` config field to your application id, otherwise it will not be possible to get a valid OpenID Connect well-known configuration and thereby verify the JWT token.
499555

500556
### GitHub
501557

558+
**Provider support:**
559+
560+
&nbsp; PKCE<br>
561+
&nbsp; Nonce<br>
562+
&nbsp; State<br>
563+
&nbsp; Access Token validation<br>
564+
&nbsp; ID Token validation<br>
565+
566+
**Instructions**
567+
502568
GitHub is not strictly an OIDC provider, but it can be used as one. Make sure that validation is disabled and that you keep the `skipAccessTokenParsing` option to `true`.
503569

504570
Try to use a [GitHub App](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/differences-between-github-apps-and-oauth-apps), not the legacy OAuth app. They don't provide the same level of security, have no granular permissions, don't provide refresh tokens and are not tested.
@@ -507,8 +573,31 @@ Make sure to set the callback URL in your OAuth app settings as `<your-domain>/a
507573

508574
### Keycloak
509575

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`.
576+
**Provider support:**
577+
578+
&nbsp; PKCE<br>
579+
&nbsp; Nonce<br>
580+
&nbsp; State<br>
581+
&nbsp; Access Token validation<br>
582+
&nbsp; ID Token validation<br>
583+
584+
**Instructions**
585+
586+
Additional parameters to be used in additionalAuthParameters,
587+
additionalTokenParameters or additionalLogoutParameters:
588+
589+
| Option | Type | Default | Description |
590+
|---|---|---|---|
591+
| realm | `string` | - | Optional. This parameter allows to slightly customize the login flow on the Keycloak server side. For example, enforce displaying the login screen in case of value login. |
592+
| realm | `string` | - | Optional. Used to pre-fill the username/email field on the login form. |
593+
| realm | `string` | - | Optional. Used to tell Keycloak to skip showing the login page and automatically redirect to the specified identity provider instead. |
594+
| realm | `string` | - | Optional. Sets the 'ui_locales' query param. |
595+
596+
For more information on these parameters, check the [KeyCloak documentation](https://www.keycloak.org/docs/latest/securing_apps/#methods).
597+
598+
For Keycloak you have to provide at least the `baseUrl`, `clientId` and `clientSecret` properties. The `baseUrl` is used to dynamically create the `authorizationUrl`, `tokenUrl`, `logoutUrl` and `userInfoUrl`.
511599
Please include the realm you want to use in the `baseUrl` (e.g. `https://<keycloak-url>/realms/<realm>`).
600+
If you don't want to use the post logout redirect feature of key cloak, set `logoutUrl` to `undefined` or `''`.
512601
Also remember to enable `Client authentication` to be able to get a client secret.
513602

514603
## Dev mode
@@ -543,7 +632,7 @@ The properties on the generated token are
543632
- `sub`: `devMode.subject` setting, default `nuxt:oidc:auth:subject`
544633
- `exp`: current DateTime + 24h
545634

546-
:warning: The access token will be generated with a fixed local secret and can in no way be considered secure. Dev mode can only be enabled in local development and should exclusively be used there for testing purposes. Never set any environment variables on your production systems that could put any component into development mode.
635+
⚠️ The access token will be generated with a fixed local secret and can in no way be considered secure. Dev mode can only be enabled in local development and should exclusively be used there for testing purposes. Never set any environment variables on your production systems that could put any component into development mode.
547636

548637
## Contributing
549638

playground/nuxt.config.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ export default defineNuxtConfig({
2323
responseType: 'code id_token',
2424
scope: ['profile', 'openid', 'offline_access', 'email'],
2525
logoutUrl: '',
26-
optionalClaims: ['unique_name', 'family_name', 'given_name'],
26+
optionalClaims: ['unique_name', 'family_name', 'given_name', 'login_hint'],
2727
audience: '',
2828
additionalAuthParameters: {
2929
resource: '',
3030
prompt: 'select_account',
3131
},
32-
validateAccessToken: false,
33-
validateIdToken: true,
34-
exposeIdToken: false,
35-
exposeAccessToken: true,
32+
additionalLogoutParameters: {
33+
logoutHint: '',
34+
},
35+
exposeIdToken: true,
36+
exposeAccessToken: false,
3637
allowedClientAuthParameters: [
3738
'test',
3839
],
@@ -64,7 +65,7 @@ export default defineNuxtConfig({
6465
clientId: '',
6566
clientSecret: '',
6667
redirectUri: 'http://localhost:3000/auth/keycloak/callback',
67-
exposeAccessToken: true,
68+
exposeAccessToken: false,
6869
userNameClaim: 'preferred_username',
6970
},
7071
cognito: {
@@ -74,7 +75,6 @@ export default defineNuxtConfig({
7475
scope: ['openid', 'email', 'profile'],
7576
logoutRedirectUri: 'https://google.com',
7677
baseUrl: '',
77-
openIdConfiguration: '',
7878
}
7979
},
8080
session: {

playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"@iconify-json/simple-icons": "^1.2.3",
1818
"@nuxtjs/color-mode": "^3.5.1",
1919
"@unocss/nuxt": "^0.62.4",
20-
"nuxt-oidc-auth": "latest"
20+
"nuxt-oidc-auth": "workspace:^"
2121
}
2222
}

playground/pages/auth/login.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ definePageMeta({
44
})
55
const { currentProvider, login, user } = useOidcAuth()
66
const { providers } = useProviders(currentProvider.value as string)
7+
// use `@click="login(provider.name as any, { test: 'thiswillappearinentra', test2: 'thiswillbeignored' })"` for testing the logout params
78
</script>
89

910
<template>
@@ -13,7 +14,7 @@ const { providers } = useProviders(currentProvider.value as string)
1314
:key="index"
1415
class="btn-base btn-login"
1516
:disabled="provider.disabled"
16-
@click="login(provider.name as any, { test: 'thiswillappearinentra', test2: 'thiswillbeignored' })"
17+
@click="login(provider.name as any)"
1718
>
1819
<span :class="provider.icon" />
1920
<span class="pl-2">{{ provider.label }}</span>

playground/pages/index.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
const { loggedIn, user, refresh, login, logout, currentProvider, clear } = useOidcAuth()
2+
const { loggedIn, user, refresh, fetch, login, logout, currentProvider, clear } = useOidcAuth()
33
const { providers } = useProviders(currentProvider.value as string)
44
</script>
55

@@ -36,6 +36,14 @@ const { providers } = useProviders(currentProvider.value as string)
3636
<span class="i-majesticons-refresh" />
3737
<span class="pl-2">Refresh</span>
3838
</button>
39+
<button
40+
class="btn-base btn-login"
41+
:disabled="!loggedIn"
42+
@click="fetch()"
43+
>
44+
<span class="i-majesticons-refresh" />
45+
<span class="pl-2">Fetch</span>
46+
</button>
3947
<button
4048
class="btn-base btn-login"
4149
:disabled="!loggedIn"

0 commit comments

Comments
 (0)