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
> :warning: The version shown in this sample may be older than the current version. We recommend using the highest version available
@@ -182,7 +183,7 @@ const oktaAuth = new OktaAuth({
182
183
})
183
184
```
184
185
185
-
However, if you're using a bundler like [Webpack](https://webpack.github.io/) or [Browserify](http://browserify.org/), you can simply import the module or require using CommonJS.
186
+
However, if you're using a bundler like [Webpack](https://webpack.github.io/) or [Rollup](https://rollupjs.org/) you can simply import or require the module.
186
187
187
188
```javascript
188
189
// ES module
@@ -198,7 +199,7 @@ var authClient = new OktaAuth(/* configOptions */);
198
199
199
200
## Usage guide
200
201
201
-
For an overview of the client's features and authentication flows, check out [our developer docs](https://developer.okta.com/code/javascript/okta_auth_sdk). There, you will learn how to use the Auth SDK on a simple static page to:
202
+
For an overview of the client's features and authentication flows, check out [our developer docs](https://developer.okta.com/docs/guides/auth-js/main/). There, you will learn how to use the Auth SDK on a simple static page to:
202
203
203
204
* Retrieve and store an OpenID Connect (OIDC) token
204
205
* Get an Okta session
@@ -213,20 +214,9 @@ You can also browse the full [API reference documentation](#api-reference).
213
214
214
215
```javascript
215
216
var config = {
216
-
// Required config
217
217
issuer:'https://{yourOktaDomain}/oauth2/default',
218
-
219
-
// Required for login flow using getWithRedirect()
Typescript versions prior to 3.6 have no type definitions for WebAuthn.
283
-
Support for WebAuthn in IDX API was introduced in `OktaAuth 6.1.0`.
273
+
Support for WebAuthn in IDX API was introduced in `@okta/okta-auth-js@6.1.0`.
284
274
To solve this issue please install package `@types/webappsec-credential-management` version `^0.5.1`.
285
275
286
276
### Strategies for Obtaining Tokens
287
277
288
278
#### Authorization Code flow for web and native client types
289
279
290
-
Web and native clients can obtain tokens using the `authorization_code` flow which uses a client secret stored in a secure location. SPA applications should use the `PKCE` flow which does not use a client secret. To use the `authorization_code` flow, set `responseType` to `"code"` and `pkce` to `false`:
280
+
Web and native clients can obtain tokens using the `authorization_code` flow which uses a client secret stored in a secure location. (SPA applications should use the `PKCE` flow which does not use a client secret) To use the `authorization_code` flow, set `responseType` to `"code"` and `pkce` to `false`:
291
281
292
282
```javascript
293
283
var config = {
@@ -306,14 +296,16 @@ var authClient = new OktaAuth(config);
306
296
307
297
#### PKCE OAuth 2.0 flow
308
298
309
-
The PKCE OAuth flow will be used by default. This library includes built-in support for Node applications. PKCE is widely supported by most modern browsers when running on an HTTPS connection. PKCE requires that the browser implements `crypto.subtle` (also known as `webcrypto`). [Most modern browsers provide this](https://caniuse.com/#feat=cryptography) when running in a secure context (on an HTTPS connection). PKCE also requires the [TextEncoder](https://caniuse.com/#feat=textencoder) object. This is available on all major browsers except IE Edge. In this case, we recommend using a polyfill/shim such as [text-encoding](https://www.npmjs.com/package/text-encoding).
299
+
The PKCE OAuth flow will be used by default. This library supports PKCE for both browser and NodeJS applications. PKCE is widely supported by most modern browsers when running on an HTTPS connection. PKCE requires that the browser implements `crypto.subtle` (also known as `webcrypto`). [Most modern browsers provide this](https://caniuse.com/#feat=cryptography) when running in a secure context (on an HTTPS connection). PKCE also requires the [TextEncoder](https://caniuse.com/#feat=textencoder) object. This is [available on all major browsers except IE 11 and Edge < v79](https://caniuse.com/textencoder). To add support, we recommend using a polyfill/shim such as [text-encoding](https://www.npmjs.com/package/text-encoding).
310
300
311
301
If the user's browser does not support PKCE, an exception will be thrown. You can test if a browser supports PKCE before construction with this static method:
312
302
313
303
`OktaAuth.features.isPKCESupported()`
314
304
315
305
#### Implicit OAuth 2.0 flow
316
306
307
+
> :warning: We strongly discourage using the implicit flow. Use PKCE and/or client credentials if possible.
308
+
317
309
Implicit OAuth flow is available as an option if PKCE flow cannot be supported in your deployment. It is widely supported by most browsers, and can work over an insecure HTTP connection. Note that implicit flow is less secure than PKCE flow, even over HTTPS, since raw tokens are exposed in the browser's history. For this reason, we highly recommending using the PKCE flow if possible.
318
310
319
311
Implicit flow can be enabled by setting the `pkce` option to `false`
@@ -332,7 +324,6 @@ var authClient = new OktaAuth(config);
332
324
333
325
### Redirects and Routing
334
326
335
-
**!** Routing is **optional** for the callback portion of the redirect strategy. Instead you can use [popup](#tokengetwithpopupoptions) or [sign widget](https://github.com/okta/okta-signin-widget).
336
327
337
328
To sign a user in, your application must redirect the browser to the Okta-hosted sign-in page.
338
329
> **Note:** Initial redirect to Okta-hosted sign-in page starts a transaction with a stateToken lifetime set to one hour.
@@ -342,10 +333,46 @@ Depending on your preferences it is possible to use the following callback strat
342
333
343
334
#### Handling the callback without routing
344
335
336
+
Most applications will handle an OAuth callback using a special route/page, separate from the signin page. However some SPA applications have no routing logic and will want to handle everything in a single page.
337
+
338
+
345
339
1. Create / configure your auth-js instance
346
-
2. Before making **any other calls with auth-js**at the VERY BEGINNING of the app call *token.isLoginRedirect* - if this returns true, call *parseFromUrl* and save tokens in storage manager.
340
+
2. Before starting the OktaAuth service, or making **any other API calls with auth-js**, call *token.isLoginRedirect* - if this returns true, call *token.parseFromUrl* and save tokens using *tokenManager.setTokens*.
347
341
**It’s important that no other app logic runs until the async parseFromUrl / token manager logic is complete**
const { tokens } = await authClient.token.parseFromUrl(); // remember to "await" this async call
369
+
authClient.tokenManager.setTokens(tokens);
370
+
}
371
+
372
+
// normal app startup
373
+
authClient.start(); // will update auth state and call event listeners
374
+
}
375
+
```
349
376
350
377
#### Handling the callback with hash routing
351
378
@@ -356,11 +383,14 @@ Additionally, if using hash routing, we recommend using PKCE and responseMode "q
356
383
357
384
#### Handling the callback with path routing (on a dedicated route)
358
385
359
-
1. Right before redirect, save the route you are on (we recommend sessionStorage)
360
-
2. Do the redirect to okta
361
-
3. Redirect back to a dedicated route
362
-
4. Call *parseFromUrl()*, retrieve tokens, add to `tokenManager`
363
-
5. Read saved route and redirect to it
386
+
1. Define a [redirectUri](#redirecturi) that maps to a dedicated route in your app
387
+
2. Before redirect, save the current route: [setOriginalUri](#setoriginaluriuri)
388
+
3. Do the redirect to okta: [token.getWithRedirect](#tokengetwithredirectoptions)
389
+
4. After successful authentication, Okta will redirect back to the configured [redirectUri](#redirecturi), your app should load on the dedicated callback route
390
+
5. On this callback page:
391
+
1. call [token.parseFromUrl](#tokenparsefromurloptions) to retrieve tokens
392
+
2. Add tokens to the `TokenManager`: [tokenManager.setTokens](#tokenmanagersettokenstokens)
393
+
6. Read saved route and redirect to it: [getOriginalUri](#getoriginaluristate)
364
394
365
395
## Configuration reference
366
396
@@ -1886,6 +1916,15 @@ We have implemented a small SPA app, located at `./test/app/` which is used inte
1886
1916
1887
1917
The [CHANGELOG](CHANGELOG.md) contains details for all changes and links to the original PR.
1888
1918
1919
+
### From 6.x to 7.x
1920
+
1921
+
* Requires Node version 14 or higher.
1922
+
* If using OIDC redirect flows with an embedded or Okta-hosted [Okta Sign-in Widget](https://github.com/okta/okta-signin-widget) widget version 5.4.0 or greater is required. [#1181](https://github.com/okta/okta-auth-js/pull/1181)
1923
+
* If using direct authentication with the IDX API:
1924
+
* Server responses with a non-200 status code will not be thrown as exceptions. If a request results in an error response from the server, the `requestDidSucceed` property on the returned `IdxTransaction` will be set to `false`. [#1205](https://github.com/okta/okta-auth-js/pull/1205)
1925
+
*`options` field is removed from the `nextStep` property of `IdxTransaction`. [#1271](https://github.com/okta/okta-auth-js/pull/1271)
1926
+
*`shoudldProceedWithEmailAuthenticator` option is removed. [#1274](https://github.com/okta/okta-auth-js/pull/1274)
1927
+
1889
1928
### From 5.x to 6.x
1890
1929
1891
1930
* All async [IDX API](docs/idx.md) methods will either resolve with an IDX transaction object or throw an exception. In the previous version some exceptions were caught and returned as the `error` property on an IDX transaction object.
0 commit comments