Skip to content

Commit 6e1461a

Browse files
authored
fix(auth0): set token and logout endpoint, and update docs (#730)
* - auth0: add token and logout endpoint * - auth0: logout endpoint is now always set * - auth0: update docs regarding logout * - auth0: set correct logout option in docs * - oauth: document logoutRedirectUri option
1 parent eba51b3 commit 6e1461a

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

docs/providers/auth0.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,23 @@ You can get your `clientId` and `domain` the Settings section for your client in
4545

4646
## Logout with new Auth0 tenants
4747

48-
Auth0 tenants created in 2018 and earlier had an optional tenant setting `Enable Seamless SSO`. This setting is automatically enabled for new tenants and cannot be disabled.
48+
On logout, local `auth` is reset and you will be instantly redirected to `Auth0` so your session is destroyed remotely as well. After that, you will be redirected back to your website by `Auth0`.
4949

50-
If enabled and a user logs out and logs back in a short while later, they will not need to re-enter their credentials. They'll be logged in automatically.
50+
To make sure you are redirected to the right page, you need to setup two things:
51+
* Go to into the `Tenant Settings` > `Advanced` and enter the allowed URL(s) you can redirect to in `Allowed Logout URLs`, such as `http://localhost:3000`
52+
* Add `logoutRedirectUri` to your config and add the value you just configured:
53+
```js
54+
auth: {
55+
strategies: {
56+
auth0: {
57+
logoutRedirectUri: 'http://localhost:3000',
58+
}
59+
}
60+
}
61+
```
5162

52-
You can force Auth0 to present the login page:
53-
* Go to into the `Tenant Settings` > `Advanced`
54-
* In `Allowed Logout URLs` enter the allowed URL(s) you can redirect to, such as `http://localhost:3000`
63+
Now you can logout calling the `logout` function:
5564

56-
Wherever you have a logout feature do two things:
57-
1. run the logout command
5865
```js
5966
this.$auth.logout()
60-
```
61-
2. redirect the user to the Auth0 logout URL along with a `returnTo` parameter
62-
```
63-
https://mytenant.auth0.com/v2/logout?returnTo=http%3A%2F%2Flocalhost:3000
6467
```

docs/schemes/oauth2.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ auth: {
4949
grantType: 'authorization_code',
5050
accessType: undefined,
5151
redirectUri: undefined,
52+
logoutRedirectUri: undefined,
5253
clientId: 'SET_ME',
5354
scope: ['openid', 'profile', 'email'],
5455
state: 'UNIQUE_AND_NON_GUESSABLE',
@@ -149,6 +150,10 @@ Should be same as login page or relative path to welcome screen. ([example](http
149150

150151
By default it will be inferred from `redirect.callback` option. (Defaults to `/login`)
151152

153+
### `logoutRedirectUri`
154+
155+
Should be an absolute path to the welcome screen
156+
152157
### `clientId`
153158

154159
**REQUIRED** - oauth2 client id.

src/providers/auth0/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export default function auth0 (_nuxt, strategy) {
66
scheme: path.resolve(__dirname, 'scheme'),
77
endpoints: {
88
authorization: `https://${strategy.domain}/authorize`,
9-
userInfo: `https://${strategy.domain}/userinfo`
9+
userInfo: `https://${strategy.domain}/userinfo`,
10+
token: `https://${strategy.domain}/oauth/token`,
11+
logout: `https://${strategy.domain}/v2/logout`
1012
},
1113
scope: ['openid', 'profile', 'email']
1214
})

src/providers/auth0/scheme.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ export default class Auth0 extends Oauth2Scheme {
55
logout () {
66
this.$auth.reset()
77

8-
if (this.options.endpoints.logout) {
9-
const opts = {
10-
client_id: this.options.clientId,
11-
returnTo: this._logoutRedirectURI
12-
}
13-
const url = this.options.endpoints.logout + '?' + encodeQuery(opts)
14-
window.location.replace(url)
8+
const opts = {
9+
client_id: this.options.clientId,
10+
returnTo: this._logoutRedirectURI
1511
}
12+
const url = this.options.endpoints.logout + '?' + encodeQuery(opts)
13+
window.location.replace(url)
1614
}
1715
}

0 commit comments

Comments
 (0)