Skip to content

Commit a57a689

Browse files
update README for 7.0.0 release (#1310)
OKTA-529706 update README for 7.0.0 release
1 parent 51a48ef commit a57a689

File tree

1 file changed

+75
-36
lines changed

1 file changed

+75
-36
lines changed

README.md

Lines changed: 75 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ This library uses semantic versioning and follows Okta's [library version policy
4141

4242
| Version | Status |
4343
| ------- | -------------------------------- |
44-
| `6.x` | :heavy_check_mark: Stable |
44+
| `7.x` | :heavy_check_mark: Stable |
45+
| `6.x` | :warning: Retiring on 2023-09-30 |
4546
| `5.x` | :warning: Retiring on 2022-10-31 |
4647
| `4.x` | :x: Retired |
4748
| `3.x` | :x: Retired |
@@ -94,7 +95,7 @@ require('@okta/okta-auth-js/polyfill');
9495
The built polyfill bundle is also available on our global CDN. Include the following script in your HTML file to load before any other scripts:
9596

9697
```html
97-
<script src="https://global.oktacdn.com/okta-auth-js/5.2.2/okta-auth-js.polyfill.js" type="text/javascript"></script>
98+
<script src="https://global.oktacdn.com/okta-auth-js/7.0.0/okta-auth-js.polyfill.js" type="text/javascript"></script>
9899
```
99100

100101
> :warning: The version shown in this sample may be older than the current version. We recommend using the highest version available
@@ -169,7 +170,7 @@ If you are using the JS on a web page from the browser, you can copy the `node_m
169170
The built library bundle is also available on our global CDN. Include the following script in your HTML file to load before your application script:
170171

171172
```html
172-
<script src="https://global.oktacdn.com/okta-auth-js/5.2.2/okta-auth-js.min.js" type="text/javascript"></script>
173+
<script src="https://global.oktacdn.com/okta-auth-js/7.0.0/okta-auth-js.min.js" type="text/javascript"></script>
173174
```
174175

175176
> :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({
182183
})
183184
```
184185

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.
186187

187188
```javascript
188189
// ES module
@@ -198,7 +199,7 @@ var authClient = new OktaAuth(/* configOptions */);
198199

199200
## Usage guide
200201

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:
202203

203204
* Retrieve and store an OpenID Connect (OIDC) token
204205
* Get an Okta session
@@ -213,20 +214,9 @@ You can also browse the full [API reference documentation](#api-reference).
213214

214215
```javascript
215216
var config = {
216-
// Required config
217217
issuer: 'https://{yourOktaDomain}/oauth2/default',
218-
219-
// Required for login flow using getWithRedirect()
220218
clientId: 'GHtf9iJdr60A9IYrR0jw',
221219
redirectUri: 'https://acme.com/oauth2/callback/home',
222-
223-
// Parse authorization code from hash fragment instead of search query
224-
responseMode: 'fragment',
225-
226-
// Configure TokenManager to use sessionStorage instead of localStorage
227-
tokenManager: {
228-
storage: 'sessionStorage'
229-
}
230220
};
231221

232222
var authClient = new OktaAuth(config);
@@ -242,52 +232,52 @@ By default, creating a new instance of `OktaAuth` will not create any asynchrono
242232
await authClient.stop(); // stop the service
243233
```
244234

245-
Starting the service will also call [authStateManager.updateAuthState](#authstatemanagerupdateauthstate).
235+
> **Note:** Starting the service will also call [authStateManager.updateAuthState](#authstatemanagerupdateauthstate).
246236
247237
### Usage with Typescript
248238

249-
Types are implicitly provided by this library through the `types` entry in `package.json`. Types can also be referenced explicitly by importing them.
239+
Type definitions are provided implicitly through the `types` entry in `package.json`. Types can also be referenced explicitly by importing them.
250240

251241
```typescript
252242
import {
253243
OktaAuth,
254244
OktaAuthOptions,
255-
TokenManager,
245+
TokenManagerInterface,
256246
AccessToken,
257247
IDToken,
258248
UserClaims,
259249
TokenParams
260-
} from '@okta/okta-auth-js'
250+
} from '@okta/okta-auth-js';
261251

262252
const config: OktaAuthOptions = {
263253
issuer: 'https://{yourOktaDomain}'
264-
}
254+
};
265255

266-
const authClient: OktaAuth = new OktaAuth(config)
267-
const tokenManager: TokenManager = authClient.tokenManager;
256+
const authClient: OktaAuth = new OktaAuth(config);
257+
const tokenManager: TokenManagerInterface = authClient.tokenManager;
268258
const accessToken: AccessToken = await tokenManager.get('accessToken') as AccessToken;
269259
const idToken: IDToken = await tokenManager.get('idToken') as IDToken;
270-
const userInfo: UserClaims = await authClient.getUserInfo(accessToken, idToken);
260+
const userInfo: UserClaims = await authClient.token.getUserInfo(accessToken, idToken);
271261

272262
if (!userInfo) {
273263
const tokenParams: TokenParams = {
274264
scopes: ['openid', 'email', 'custom_scope'],
275-
}
265+
};
276266
authClient.token.getWithRedirect(tokenParams);
277267
}
278268
```
279269

280270
#### Usage with Typescript < 3.6
281271

282272
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`.
284274
To solve this issue please install package `@types/webappsec-credential-management` version `^0.5.1`.
285275

286276
### Strategies for Obtaining Tokens
287277

288278
#### Authorization Code flow for web and native client types
289279

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`:
291281

292282
```javascript
293283
var config = {
@@ -306,14 +296,16 @@ var authClient = new OktaAuth(config);
306296

307297
#### PKCE OAuth 2.0 flow
308298

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).
310300

311301
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:
312302

313303
`OktaAuth.features.isPKCESupported()`
314304

315305
#### Implicit OAuth 2.0 flow
316306

307+
> :warning: We strongly discourage using the implicit flow. Use PKCE and/or client credentials if possible.
308+
317309
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.
318310

319311
Implicit flow can be enabled by setting the `pkce` option to `false`
@@ -332,7 +324,6 @@ var authClient = new OktaAuth(config);
332324

333325
### Redirects and Routing
334326

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).
336327

337328
To sign a user in, your application must redirect the browser to the Okta-hosted sign-in page.
338329
> **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
342333

343334
#### Handling the callback without routing
344335

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+
345339
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*.
347341
**It’s important that no other app logic runs until the async parseFromUrl / token manager logic is complete**
348-
3. After continue normal app logic
342+
3. After this, continue normal app logic
343+
344+
```
345+
346+
async function main() {
347+
// create OktaAuth instance
348+
var config = {
349+
issuer: 'https://{yourOktaDomain}/oauth2/default',
350+
clientId: 'GHtf9iJdr60A9IYrR0jw',
351+
redirectUri: 'https://acme.com/oauth2/callback/home',
352+
};
353+
authClient = new OktaAuth(config);
354+
355+
// Subscribe to authState change event.
356+
authClient.authStateManager.subscribe(function(authState) {
357+
// Logic based on authState is done here.
358+
if (!authState.isAuthenticated) {
359+
// render unathenticated view
360+
return;
361+
}
362+
363+
// Render authenticated view
364+
});
365+
366+
// Handle callback
367+
if (authClient.token.isLoginRedirect()) {
368+
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+
```
349376

350377
#### Handling the callback with hash routing
351378

@@ -356,11 +383,14 @@ Additionally, if using hash routing, we recommend using PKCE and responseMode "q
356383

357384
#### Handling the callback with path routing (on a dedicated route)
358385

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)
364394

365395
## Configuration reference
366396

@@ -1886,6 +1916,15 @@ We have implemented a small SPA app, located at `./test/app/` which is used inte
18861916

18871917
The [CHANGELOG](CHANGELOG.md) contains details for all changes and links to the original PR.
18881918

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+
18891928
### From 5.x to 6.x
18901929

18911930
* 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

Comments
 (0)