@auth0/auth0-react 1.12.0 → 1.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -146
- package/dist/auth0-react.cjs.js +6 -6
- package/dist/auth0-react.cjs.js.map +1 -1
- package/dist/auth0-react.esm.js +4 -4
- package/dist/auth0-react.esm.js.map +1 -1
- package/dist/auth0-react.js +6 -6
- package/dist/auth0-react.js.map +1 -1
- package/dist/auth0-react.min.js +1 -1
- package/dist/auth0-react.min.js.map +1 -1
- package/package.json +21 -20
package/README.md
CHANGED
|
@@ -1,31 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
2
|
|
|
3
|
-
Auth0 SDK for React Single Page Applications (SPA).
|
|
4
|
-
|
|
5
|
-
[](https://circleci.com/gh/auth0/auth0-react)
|
|
6
|
-
[](https://opensource.org/licenses/MIT)
|
|
7
3
|
[](https://www.npmjs.com/package/@auth0/auth0-react)
|
|
8
4
|
[](https://codecov.io/gh/auth0/auth0-react)
|
|
5
|
+

|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://circleci.com/gh/auth0/auth0-react)
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- [Documentation](#documentation)
|
|
13
|
-
- [Installation](#installation)
|
|
14
|
-
- [Getting Started](#getting-started)
|
|
15
|
-
- [Contributing](#contributing)
|
|
16
|
-
- [Support + Feedback](#support--feedback)
|
|
17
|
-
- [Troubleshooting](#troubleshooting)
|
|
18
|
-
- [Frequently Asked Questions](#frequently-asked-questions)
|
|
19
|
-
- [Vulnerability Reporting](#vulnerability-reporting)
|
|
20
|
-
- [What is Auth0](#what-is-auth0)
|
|
21
|
-
- [License](#license)
|
|
9
|
+
📚 [Documentation](#documentation) - 🚀 [Getting Started](#getting-started) - 💻 [API Reference](#api-reference) - 💬 [Feedback](#feedback)
|
|
22
10
|
|
|
23
11
|
## Documentation
|
|
24
12
|
|
|
25
|
-
- [
|
|
26
|
-
- [
|
|
13
|
+
- [Quickstart](https://auth0.com/docs/quickstart/spa/react) - our interactive guide for quickly adding login, logout and user information to a React app using Auth0.
|
|
14
|
+
- [Sample App](https://github.com/auth0-samples/auth0-react-samples/tree/master/Sample-01) - a full-fledged React application integrated with Auth0.
|
|
15
|
+
- [FAQs](https://github.com/auth0/auth0-react/blob/master/FAQ.md) - frequently asked questions about the auth0-react SDK.
|
|
16
|
+
- [Examples](https://github.com/auth0/auth0-react/blob/master/EXAMPLES.md) - code samples for common React authentication scenario's.
|
|
17
|
+
- [Docs site](https://www.auth0.com/docs) - explore our docs site and learn more about Auth0.
|
|
18
|
+
|
|
19
|
+
## Getting started
|
|
27
20
|
|
|
28
|
-
|
|
21
|
+
### Installation
|
|
29
22
|
|
|
30
23
|
Using [npm](https://npmjs.org/)
|
|
31
24
|
|
|
@@ -39,7 +32,29 @@ Using [yarn](https://yarnpkg.com/)
|
|
|
39
32
|
yarn add @auth0/auth0-react
|
|
40
33
|
```
|
|
41
34
|
|
|
42
|
-
|
|
35
|
+
### Configure Auth0
|
|
36
|
+
|
|
37
|
+
Create a **Single Page Application** in the [Auth0 Dashboard](https://manage.auth0.com/#/applications).
|
|
38
|
+
|
|
39
|
+
> **If you're using an existing application**, verify that you have configured the following settings in your Single Page Application:
|
|
40
|
+
>
|
|
41
|
+
> - Click on the "Settings" tab of your application's page.
|
|
42
|
+
> - Ensure that "Token Endpoint Authentication Method" under "Application Properties" is set to "None"
|
|
43
|
+
> - Scroll down and click on the "Show Advanced Settings" link.
|
|
44
|
+
> - Under "Advanced Settings", click on the "OAuth" tab.
|
|
45
|
+
> - Ensure that "JsonWebToken Signature Algorithm" is set to `RS256` and that "OIDC Conformant" is enabled.
|
|
46
|
+
|
|
47
|
+
Next, configure the following URLs for your application under the "Application URIs" section of the "Settings" page:
|
|
48
|
+
|
|
49
|
+
- **Allowed Callback URLs**: `http://localhost:3000`
|
|
50
|
+
- **Allowed Logout URLs**: `http://localhost:3000`
|
|
51
|
+
- **Allowed Web Origins**: `http://localhost:3000`
|
|
52
|
+
|
|
53
|
+
> These URLs should reflect the origins that your application is running on. **Allowed Callback URLs** may also include a path, depending on where you're handling the callback.
|
|
54
|
+
|
|
55
|
+
Take note of the **Client ID** and **Domain** values under the "Basic Information" section. You'll need these values in the next step.
|
|
56
|
+
|
|
57
|
+
### Configure the SDK
|
|
43
58
|
|
|
44
59
|
Configure the SDK by wrapping your application in `Auth0Provider`:
|
|
45
60
|
|
|
@@ -70,14 +85,8 @@ import React from 'react';
|
|
|
70
85
|
import { useAuth0 } from '@auth0/auth0-react';
|
|
71
86
|
|
|
72
87
|
function App() {
|
|
73
|
-
const {
|
|
74
|
-
|
|
75
|
-
isAuthenticated,
|
|
76
|
-
error,
|
|
77
|
-
user,
|
|
78
|
-
loginWithRedirect,
|
|
79
|
-
logout,
|
|
80
|
-
} = useAuth0();
|
|
88
|
+
const { isLoading, isAuthenticated, error, user, loginWithRedirect, logout } =
|
|
89
|
+
useAuth0();
|
|
81
90
|
|
|
82
91
|
if (isLoading) {
|
|
83
92
|
return <div>Loading...</div>;
|
|
@@ -103,101 +112,21 @@ function App() {
|
|
|
103
112
|
export default App;
|
|
104
113
|
```
|
|
105
114
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
```ts
|
|
109
|
-
const { user } = useAuth0<{ name: string }>();
|
|
110
|
-
|
|
111
|
-
user.name; // is a string
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### Use with a Class Component
|
|
115
|
-
|
|
116
|
-
Use the `withAuth0` higher order component to add the `auth0` property to Class components:
|
|
117
|
-
|
|
118
|
-
```jsx
|
|
119
|
-
import React, { Component } from 'react';
|
|
120
|
-
import { withAuth0 } from '@auth0/auth0-react';
|
|
121
|
-
|
|
122
|
-
class Profile extends Component {
|
|
123
|
-
render() {
|
|
124
|
-
// `this.props.auth0` has all the same properties as the `useAuth0` hook
|
|
125
|
-
const { user } = this.props.auth0;
|
|
126
|
-
return <div>Hello {user.name}</div>;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export default withAuth0(Profile);
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### Protect a Route
|
|
134
|
-
|
|
135
|
-
Protect a route component using the `withAuthenticationRequired` higher order component. Visits to this route when unauthenticated will redirect the user to the login page and back to this page after login:
|
|
115
|
+
For more code samples on how to integrate **auth0-react** SDK in your **React** application, have a look at our [examples](https://github.com/auth0/auth0-react/blob/master/EXAMPLES.md).
|
|
136
116
|
|
|
137
|
-
|
|
138
|
-
import React from 'react';
|
|
139
|
-
import { withAuthenticationRequired } from '@auth0/auth0-react';
|
|
140
|
-
|
|
141
|
-
const PrivateRoute = () => <div>Private</div>;
|
|
142
|
-
|
|
143
|
-
export default withAuthenticationRequired(PrivateRoute, {
|
|
144
|
-
// Show a message while the user waits to be redirected to the login page.
|
|
145
|
-
onRedirecting: () => <div>Redirecting you to the login page...</div>,
|
|
146
|
-
});
|
|
147
|
-
```
|
|
117
|
+
## API reference
|
|
148
118
|
|
|
149
|
-
|
|
119
|
+
Explore public API's available in auth0-react.
|
|
150
120
|
|
|
151
|
-
|
|
121
|
+
- [Auth0Provider](https://auth0.github.io/auth0-react/modules.html#Auth0Provider)
|
|
122
|
+
- [Auth0ProviderOptions](https://auth0.github.io/auth0-react/interfaces/Auth0ProviderOptions.html)
|
|
123
|
+
- [useAuth0](https://auth0.github.io/auth0-react/modules.html#useAuth0)
|
|
124
|
+
- [withAuth0](https://auth0.github.io/auth0-react/modules.html#withAuth0)
|
|
125
|
+
- [withAuthenticationRequired](https://auth0.github.io/auth0-react/modules.html#withAuthenticationRequired)
|
|
152
126
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
```jsx
|
|
156
|
-
import React, { useEffect, useState } from 'react';
|
|
157
|
-
import { useAuth0 } from '@auth0/auth0-react';
|
|
158
|
-
|
|
159
|
-
const Posts = () => {
|
|
160
|
-
const { getAccessTokenSilently } = useAuth0();
|
|
161
|
-
const [posts, setPosts] = useState(null);
|
|
162
|
-
|
|
163
|
-
useEffect(() => {
|
|
164
|
-
(async () => {
|
|
165
|
-
try {
|
|
166
|
-
const token = await getAccessTokenSilently({
|
|
167
|
-
audience: 'https://api.example.com/',
|
|
168
|
-
scope: 'read:posts',
|
|
169
|
-
});
|
|
170
|
-
const response = await fetch('https://api.example.com/posts', {
|
|
171
|
-
headers: {
|
|
172
|
-
Authorization: `Bearer ${token}`,
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
setPosts(await response.json());
|
|
176
|
-
} catch (e) {
|
|
177
|
-
console.error(e);
|
|
178
|
-
}
|
|
179
|
-
})();
|
|
180
|
-
}, [getAccessTokenSilently]);
|
|
181
|
-
|
|
182
|
-
if (!posts) {
|
|
183
|
-
return <div>Loading...</div>;
|
|
184
|
-
}
|
|
127
|
+
## Feedback
|
|
185
128
|
|
|
186
|
-
|
|
187
|
-
<ul>
|
|
188
|
-
{posts.map((post, index) => {
|
|
189
|
-
return <li key={index}>{post}</li>;
|
|
190
|
-
})}
|
|
191
|
-
</ul>
|
|
192
|
-
);
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
export default Posts;
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
For a more detailed example see how to [create a `useApi` hook for accessing protected APIs with an access token](https://github.com/auth0/auth0-react/blob/master/EXAMPLES.md#4-create-a-useapi-hook-for-accessing-protected-apis-with-an-access-token).
|
|
199
|
-
|
|
200
|
-
## Contributing
|
|
129
|
+
### Contributing
|
|
201
130
|
|
|
202
131
|
We appreciate feedback and contribution to this repo! Before you get started, please see the following:
|
|
203
132
|
|
|
@@ -205,35 +134,23 @@ We appreciate feedback and contribution to this repo! Before you get started, pl
|
|
|
205
134
|
- [Auth0's code of conduct guidelines](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)
|
|
206
135
|
- [This repo's contribution guide](https://github.com/auth0/auth0-react/blob/master/CONTRIBUTING.md)
|
|
207
136
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
For support or to provide feedback, please [raise an issue on our issue tracker](https://github.com/auth0/auth0-react/issues).
|
|
211
|
-
|
|
212
|
-
## Troubleshooting
|
|
213
|
-
|
|
214
|
-
For information on how to solve common problems, check out the [Troubleshooting](https://github.com/auth0/auth0-react/blob/master/TROUBLESHOOTING.md) guide
|
|
215
|
-
|
|
216
|
-
## Frequently Asked Questions
|
|
217
|
-
|
|
218
|
-
For a rundown of common issues you might encounter when using the SDK, please check out the [FAQ](https://github.com/auth0/auth0-react/blob/master/FAQ.md).
|
|
219
|
-
|
|
220
|
-
## Vulnerability Reporting
|
|
221
|
-
|
|
222
|
-
Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/whitehat) details the procedure for disclosing security issues.
|
|
223
|
-
|
|
224
|
-
## What is Auth0?
|
|
137
|
+
### Raise an issue
|
|
225
138
|
|
|
226
|
-
|
|
139
|
+
To provide feedback or report a bug, please [raise an issue on our issue tracker](https://github.com/auth0/auth0-react/issues).
|
|
227
140
|
|
|
228
|
-
|
|
229
|
-
- Log in users with username/password databases, passwordless, or multi-factor authentication
|
|
230
|
-
- Link multiple user accounts together
|
|
231
|
-
- Generate signed JSON Web Tokens to authorize your API calls and flow the user identity securely
|
|
232
|
-
- Access demographics and analytics detailing how, when, and where users are logging in
|
|
233
|
-
- Enrich user profiles from other data sources using customizable JavaScript rules
|
|
141
|
+
### Vulnerability Reporting
|
|
234
142
|
|
|
235
|
-
[
|
|
143
|
+
Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](https://auth0.com/responsible-disclosure-policy) details the procedure for disclosing security issues.
|
|
236
144
|
|
|
237
|
-
|
|
145
|
+
---
|
|
238
146
|
|
|
239
|
-
|
|
147
|
+
<p align="center">
|
|
148
|
+
<picture>
|
|
149
|
+
<source media="(prefers-color-scheme: light)" srcset="https://cdn.auth0.com/website/sdks/logos/auth0_light_mode.png" width="150">
|
|
150
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://cdn.auth0.com/website/sdks/logos/auth0_dark_mode.png" width="150">
|
|
151
|
+
<img alt="Auth0 Logo" src="https://cdn.auth0.com/website/sdks/logos/auth0_light_mode.png" width="150">
|
|
152
|
+
</picture>
|
|
153
|
+
</p>
|
|
154
|
+
<p align="center">Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout <a href="https://auth0.com/why-auth0">Why Auth0?</a></p>
|
|
155
|
+
<p align="center">
|
|
156
|
+
This project is licensed under the MIT license. See the <a href="https://github.com/auth0/auth0-react/blob/master/LICENSE"> LICENSE</a> file for more info.</p>
|