Skip to content

Commit 3bf208e

Browse files
authored
Migrating from renewAuth to checkSession (#68)
* Migrating from renewAuth to checkSession * removing api from example 05 * fixing pr comments
1 parent d6eaefa commit 3bf208e

10 files changed

Lines changed: 25 additions & 186 deletions

File tree

05-Token-Renewal/.env.example

Lines changed: 0 additions & 2 deletions
This file was deleted.

05-Token-Renewal/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Auth0 React Token Renewal
22

3-
This sample demonstrates how to silently renew `access_token`s in a React application with Auth0. The sample uses the create-react-app.
3+
This sample demonstrates how to renew `access_token`s in a React application with Auth0 using `checkSession`. For more information, read [our reference documentation](https://auth0.com/docs/libraries/auth0js#using-checksession-to-acquire-new-tokens). The sample uses the create-react-app.
44

55
## Getting Started
66

@@ -18,11 +18,9 @@ npm install
1818

1919
If you download the sample from the quickstart page, it will come pre-populated with the **client ID** and **domain** for your application. If you clone the repo directly from Github, rename the `auth0-variables.js.example` file to `auth0-variables.js` and provide the **client ID** and **domain** there. This file is located in `src/Auth/`.
2020

21-
You should also provide the identifier for the API you create in the Auth0 dashboard as your `apiUrl`.
21+
## Set Up `Allowed Web Origins` in the dashboard
2222

23-
## Set Up the `silent.html` File
24-
25-
If you download the sample from the quickstart page, it will come pre-populated with the **client ID** and **domain** for your application. If you clone the repo directly from Github, edit `silent.html` and add your **client ID** and **domain**.
23+
In order to make `checkSession` work, you need to add the URL where the authorization request originates from, to the Allowed Web Origins list of your Auth0 client in the Dashboard under your client's Settings.
2624

2725
## Run the Application
2826

05-Token-Renewal/package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,17 @@
66
"react-scripts": "1.0.10"
77
},
88
"dependencies": {
9-
"auth0-js": "^8.8.0",
9+
"auth0-js": "^8.12.1",
1010
"bootstrap": "^3.3.7",
11-
"connect-static-file": "^1.2.0",
12-
"cors": "^2.8.4",
13-
"express": "^4.15.3",
14-
"npm-run-all": "^4.0.2",
1511
"react": "^15.6.1",
1612
"react-bootstrap": "^0.31.2",
1713
"react-dom": "^15.6.1",
1814
"react-router": "^4.1.2",
1915
"react-router-dom": "^4.1.2"
2016
},
2117
"scripts": {
22-
"start": "npm-run-all --parallel server:start client:start",
18+
"start": "npm run client:start",
2319
"client:start": "react-scripts start",
24-
"server:start": "node server.js",
2520
"build": "react-scripts build",
2621
"test": "react-scripts test --env=jsdom",
2722
"eject": "react-scripts eject"

05-Token-Renewal/server.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

05-Token-Renewal/silent.html

Lines changed: 0 additions & 15 deletions
This file was deleted.

05-Token-Renewal/src/Auth/Auth.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export default class Auth {
1010
domain: AUTH_CONFIG.domain,
1111
clientID: AUTH_CONFIG.clientId,
1212
redirectUri: AUTH_CONFIG.callbackUrl,
13-
audience: AUTH_CONFIG.apiUrl,
1413
responseType: 'token id_token',
1514
scope: 'openid profile'
1615
});
@@ -97,17 +96,11 @@ export default class Auth {
9796
}
9897

9998
renewToken() {
100-
this.auth0.renewAuth(
101-
{
102-
audience: AUTH_CONFIG.apiUrl,
103-
redirectUri: AUTH_CONFIG.silentAuthRedirect,
104-
usePostMessage: true,
105-
postMessageDataType: 'auth0:silent-authentication',
106-
},
99+
this.auth0.checkSession({},
107100
(err, result) => {
108101
if (err) {
109102
alert(
110-
`Could not get a new token using silent authentication (${err.error}).`
103+
`Could not get a new token (${err.error}: ${err.error_description}).`
111104
);
112105
} else {
113106
this.setSession(result);
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
export const AUTH_CONFIG = {
22
domain: '{DOMAIN}',
33
clientId: '{CLIENT_ID}',
4-
callbackUrl: 'http://localhost:3000/callback',
5-
apiUrl: '{API_IDENTIFIER}',
6-
silentAuthRedirect: 'http://localhost:3001/silent'
4+
callbackUrl: 'http://localhost:3000/callback'
75
}

05-Token-Renewal/src/Home/Home.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class Home extends Component {
1818
{this.getExpiryDate()}
1919
</p>
2020
<p>
21-
The token has been scheduled for renewal using silent
22-
authentication, but you can also renew it manually from the navbar
21+
The token has been scheduled for renewal, but you can also renew it manually from the navbar
2322
if you don't want to wait. This manual renewal button is really
2423
just for demonstration and you probably won't want such a control
2524
in your actual application.

05-Token-Renewal/src/constants.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)