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
Before calling `React.render()` be sure to call [`ReactStormpath.init()`][]. This sets up the SDK so that it's ready to be used.
69
+
3.**Initialize the SDK**
70
+
71
+
The React SDK leverages the [Stormpath Client API][] for its authentication needs. Login to your Stormpath Tenant, and find your Client API domain (inside your application's policy section). Add your Client API domain as the `endpoints.baseUri` setting when initializing `ReactStormpath`:
89
72
90
73
```javascript
91
74
ReactStormpath.init({
92
-
// See the API docs for available configuration options.
75
+
endpoints: {
76
+
baseUri:'https://{{clientApiDomainName}}'
77
+
}
93
78
});
94
79
```
95
80
96
-
6.**Configure the Router**
81
+
4.**Configure the Router**
97
82
98
83
In the file where you setup your [React Router][] routes, change your [`ReactRouter.Router`][] to [`ReactStormpath.Router`][] as shown below:
99
84
@@ -109,7 +94,7 @@ Stormpath already integrated!*
109
94
);
110
95
```
111
96
112
-
7.**Setup your Routes**
97
+
5.**Setup your Routes**
113
98
114
99
Start by adding a route that people can go to in order to sign up. This will just be a regular [`ReactRouter.Route`][]. Then once you've done this, create a view for your route called `RegistrationPage` and add the [`RegistrationForm`][] component to it. This will render a registration form and allow people to sign up.
You just added user authentication to your React app with Stormpath, you should now be able to register and login! See the [API Documentation][] for further information on how Stormpath can be used with your React app. Once you have been able to successfully log in, the next section will discuss integrating with your own server.
197
+
198
+
11.**Making Authenticated Requests**
199
+
200
+
Once you are able to successfully authenticate (log in) from your application, you will want to authorize access to API endpoints on your server. The React SDK provides methods for getting the current authenticated access token, and using it to authenticate requests.
201
+
202
+
Imagine you have an API on your server, such as `http://localhost:3000/api/subscription`, and you want to authorize requests to this endpoint and know who the user is.
203
+
204
+
If you want to manually construct a request, using the `fetch` library, you can use our access token getter to add the access token to the request:
205
+
206
+
```javascript
207
+
ReactStormpath.getAccessToken()
208
+
.then((accessToken) => {
209
+
fetch('http://localhost:3000/api/subscription', {
210
+
method:'get',
211
+
headers: {
212
+
'Authorization':'Bearer '+ accessToken
213
+
}
214
+
});
215
+
}).catch(() => {
216
+
// Could not get access token, user is not logged in
217
+
});
218
+
```
219
+
220
+
12.**Authorizing Requests Server-Side**
221
+
222
+
Once your app has made the request with the access token, your server will need to read the token and make an authorization decision. We provide SDKs for your backend server that make this easy. Please follow one of the following links for a language-specific or framework-specific guide:
223
+
224
+
**Java**
225
+
226
+
Spring Boot developers should make use of our Spring Boot plugin, and see the [Token Management Documentation](https://docs.stormpath.com/java/spring-boot-web/tutorial.html#token-management).
227
+
228
+
**.NET**
229
+
230
+
ASP.NET developers can leverage our [ASP.NET](https://docs.stormpath.com/dotnet/aspnet/latest/) and [ASP.NET Core](https://docs.stormpath.com/dotnet/aspnetcore/latest/) libraries to achieve authorization in their applications, please see the Authorization section of each guide.
231
+
232
+
**Node.js**
233
+
234
+
Express developers can use our [Express-Stormpath](https://docs.stormpath.com/nodejs/express/latest/) library to easily authenticate requests with access tokens and make authorization decisions, please see the [Token Authentication](https://docs.stormpath.com/nodejs/express/latest/authentication.html#token-authentication) documentation.
235
+
236
+
Node applications can generically use the [Stormpath Node SDK](https://docs.stormpath.com/nodejs/jsdoc/) to validate tokens, using the [JwtAuthenticator](https://docs.stormpath.com/nodejs/jsdoc/JwtAuthenticator.html).
237
+
238
+
**PHP**
239
+
240
+
Laravel developers can use our <ahref="https://docs.stormpath.com/php/laravel/latest/index.html">Stormpath-Laravel</a> or [Stormpath-Lumen](https://docs.stormpath.com/php/lumen/latest/index.html) libraries and their respective `stormpath.auth` middleware to authenticate requests, please see the User Data section of the documentation for each library.
241
+
242
+
**Other**
243
+
244
+
Don't see your environment listed? Not a problem! Our access tokens are simple JWTs, that can be validated with most generic JWT validation libraries. Our product guide can walk you through the process, [Validating an Access Token](https://docs.stormpath.com/rest/product-guide/latest/auth_n.html#validating-an-access-token").
210
245
211
-
You just added user authentication to your app with Stormpath. See the [API Documentation][] for further information on how Stormpath can be used with your React app.
246
+
Need more assistance? Feel free to contact our support channel, details are below.
0 commit comments