@okta/okta-auth-js 5.4.3 → 5.8.0

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.
Files changed (202) hide show
  1. package/CHANGELOG.md +59 -4
  2. package/README.md +66 -977
  3. package/cjs/AuthStateManager.js +5 -0
  4. package/cjs/AuthStateManager.js.map +1 -1
  5. package/cjs/OktaAuth.js +74 -29
  6. package/cjs/OktaAuth.js.map +1 -1
  7. package/cjs/OktaUserAgent.js +2 -2
  8. package/cjs/StorageManager.js +16 -0
  9. package/cjs/StorageManager.js.map +1 -1
  10. package/cjs/TransactionManager.js +44 -8
  11. package/cjs/TransactionManager.js.map +1 -1
  12. package/cjs/browser/browserStorage.js +5 -5
  13. package/cjs/browser/browserStorage.js.map +1 -1
  14. package/cjs/builderUtil.js +6 -0
  15. package/cjs/builderUtil.js.map +1 -1
  16. package/cjs/constants.js +5 -1
  17. package/cjs/constants.js.map +1 -1
  18. package/cjs/fetch/fetchRequest.js +10 -3
  19. package/cjs/fetch/fetchRequest.js.map +1 -1
  20. package/cjs/http/request.js +4 -0
  21. package/cjs/http/request.js.map +1 -1
  22. package/cjs/idx/interact.js +5 -2
  23. package/cjs/idx/interact.js.map +1 -1
  24. package/cjs/idx/introspect.js +24 -7
  25. package/cjs/idx/introspect.js.map +1 -1
  26. package/cjs/idx/remediate.js +35 -41
  27. package/cjs/idx/remediate.js.map +1 -1
  28. package/cjs/idx/remediators/Base/AuthenticatorData.js +7 -7
  29. package/cjs/idx/remediators/Base/AuthenticatorData.js.map +1 -1
  30. package/cjs/idx/remediators/Base/Remediator.js +13 -7
  31. package/cjs/idx/remediators/Base/Remediator.js.map +1 -1
  32. package/cjs/idx/remediators/Base/SelectAuthenticator.js +6 -6
  33. package/cjs/idx/remediators/Base/SelectAuthenticator.js.map +1 -1
  34. package/cjs/idx/remediators/Base/VerifyAuthenticator.js +18 -14
  35. package/cjs/idx/remediators/Base/VerifyAuthenticator.js.map +1 -1
  36. package/cjs/idx/remediators/EnrollProfile.js +14 -0
  37. package/cjs/idx/remediators/EnrollProfile.js.map +1 -1
  38. package/cjs/idx/remediators/Identify.js +5 -2
  39. package/cjs/idx/remediators/Identify.js.map +1 -1
  40. package/cjs/idx/remediators/ReEnrollAuthenticator.js +1 -1
  41. package/cjs/idx/remediators/ReEnrollAuthenticator.js.map +1 -1
  42. package/cjs/idx/run.js +28 -6
  43. package/cjs/idx/run.js.map +1 -1
  44. package/cjs/idx/transactionMeta.js +24 -9
  45. package/cjs/idx/transactionMeta.js.map +1 -1
  46. package/cjs/idx/types/idx-js.js +5 -0
  47. package/cjs/idx/types/idx-js.js.map +1 -1
  48. package/cjs/idx/types/index.js +17 -6
  49. package/cjs/idx/types/index.js.map +1 -1
  50. package/cjs/oidc/getToken.js +14 -9
  51. package/cjs/oidc/getToken.js.map +1 -1
  52. package/cjs/oidc/getWithPopup.js +9 -2
  53. package/cjs/oidc/getWithPopup.js.map +1 -1
  54. package/cjs/oidc/getWithRedirect.js.map +1 -1
  55. package/cjs/oidc/parseFromUrl.js +59 -20
  56. package/cjs/oidc/parseFromUrl.js.map +1 -1
  57. package/cjs/oidc/renewTokens.js +28 -5
  58. package/cjs/oidc/renewTokens.js.map +1 -1
  59. package/cjs/oidc/util/browser.js +1 -13
  60. package/cjs/oidc/util/browser.js.map +1 -1
  61. package/cjs/oidc/util/loginRedirect.js +9 -5
  62. package/cjs/oidc/util/loginRedirect.js.map +1 -1
  63. package/cjs/oidc/util/urlParams.js +1 -1
  64. package/cjs/oidc/util/urlParams.js.map +1 -1
  65. package/cjs/oidc/util/validateClaims.js +8 -6
  66. package/cjs/oidc/util/validateClaims.js.map +1 -1
  67. package/cjs/options.js +15 -2
  68. package/cjs/options.js.map +1 -1
  69. package/cjs/server/serverStorage.js +2 -1
  70. package/cjs/server/serverStorage.js.map +1 -1
  71. package/cjs/tx/AuthTransaction.js +1 -3
  72. package/cjs/tx/AuthTransaction.js.map +1 -1
  73. package/cjs/tx/api.js +3 -0
  74. package/cjs/tx/api.js.map +1 -1
  75. package/cjs/types/Transaction.js.map +1 -1
  76. package/cjs/util/emailVerify.js +28 -0
  77. package/cjs/util/emailVerify.js.map +1 -0
  78. package/cjs/util/index.js +13 -0
  79. package/cjs/util/index.js.map +1 -1
  80. package/cjs/util/sharedStorage.js +54 -0
  81. package/cjs/util/sharedStorage.js.map +1 -0
  82. package/dist/okta-auth-js.min.js +2 -74
  83. package/dist/okta-auth-js.min.js.LICENSE.txt +32 -0
  84. package/dist/okta-auth-js.min.js.map +1 -1
  85. package/dist/okta-auth-js.polyfill.js +2 -18
  86. package/dist/okta-auth-js.polyfill.js.LICENSE.txt +18 -0
  87. package/dist/okta-auth-js.polyfill.js.map +1 -1
  88. package/dist/okta-auth-js.umd.js +2 -74
  89. package/dist/okta-auth-js.umd.js.LICENSE.txt +32 -0
  90. package/dist/okta-auth-js.umd.js.map +1 -1
  91. package/esm/AuthStateManager.js +5 -0
  92. package/esm/AuthStateManager.js.map +1 -1
  93. package/esm/OktaAuth.js +75 -31
  94. package/esm/OktaAuth.js.map +1 -1
  95. package/esm/OktaUserAgent.js +2 -2
  96. package/esm/StorageManager.js +17 -1
  97. package/esm/StorageManager.js.map +1 -1
  98. package/esm/TransactionManager.js +43 -8
  99. package/esm/TransactionManager.js.map +1 -1
  100. package/esm/browser/browserStorage.js +5 -5
  101. package/esm/browser/browserStorage.js.map +1 -1
  102. package/esm/builderUtil.js +6 -0
  103. package/esm/builderUtil.js.map +1 -1
  104. package/esm/constants.js +2 -0
  105. package/esm/constants.js.map +1 -1
  106. package/esm/fetch/fetchRequest.js +10 -3
  107. package/esm/fetch/fetchRequest.js.map +1 -1
  108. package/esm/http/request.js +4 -0
  109. package/esm/http/request.js.map +1 -1
  110. package/esm/idx/interact.js +5 -2
  111. package/esm/idx/interact.js.map +1 -1
  112. package/esm/idx/introspect.js +22 -6
  113. package/esm/idx/introspect.js.map +1 -1
  114. package/esm/idx/remediate.js +36 -37
  115. package/esm/idx/remediate.js.map +1 -1
  116. package/esm/idx/remediators/Base/AuthenticatorData.js +7 -7
  117. package/esm/idx/remediators/Base/AuthenticatorData.js.map +1 -1
  118. package/esm/idx/remediators/Base/Remediator.js +13 -8
  119. package/esm/idx/remediators/Base/Remediator.js.map +1 -1
  120. package/esm/idx/remediators/Base/SelectAuthenticator.js +6 -6
  121. package/esm/idx/remediators/Base/SelectAuthenticator.js.map +1 -1
  122. package/esm/idx/remediators/Base/VerifyAuthenticator.js +18 -15
  123. package/esm/idx/remediators/Base/VerifyAuthenticator.js.map +1 -1
  124. package/esm/idx/remediators/EnrollProfile.js +21 -4
  125. package/esm/idx/remediators/EnrollProfile.js.map +1 -1
  126. package/esm/idx/remediators/Identify.js +4 -2
  127. package/esm/idx/remediators/Identify.js.map +1 -1
  128. package/esm/idx/remediators/ReEnrollAuthenticator.js +1 -1
  129. package/esm/idx/remediators/ReEnrollAuthenticator.js.map +1 -1
  130. package/esm/idx/run.js +27 -6
  131. package/esm/idx/run.js.map +1 -1
  132. package/esm/idx/transactionMeta.js +23 -10
  133. package/esm/idx/transactionMeta.js.map +1 -1
  134. package/esm/idx/types/idx-js.js +3 -0
  135. package/esm/idx/types/idx-js.js.map +1 -1
  136. package/esm/idx/types/index.js +15 -5
  137. package/esm/idx/types/index.js.map +1 -1
  138. package/esm/oidc/getToken.js +15 -10
  139. package/esm/oidc/getToken.js.map +1 -1
  140. package/esm/oidc/getWithPopup.js +8 -2
  141. package/esm/oidc/getWithPopup.js.map +1 -1
  142. package/esm/oidc/getWithRedirect.js.map +1 -1
  143. package/esm/oidc/parseFromUrl.js +59 -17
  144. package/esm/oidc/parseFromUrl.js.map +1 -1
  145. package/esm/oidc/renewTokens.js +27 -5
  146. package/esm/oidc/renewTokens.js.map +1 -1
  147. package/esm/oidc/util/browser.js +1 -12
  148. package/esm/oidc/util/browser.js.map +1 -1
  149. package/esm/oidc/util/loginRedirect.js +9 -5
  150. package/esm/oidc/util/loginRedirect.js.map +1 -1
  151. package/esm/oidc/util/urlParams.js +1 -1
  152. package/esm/oidc/util/urlParams.js.map +1 -1
  153. package/esm/oidc/util/validateClaims.js +8 -6
  154. package/esm/oidc/util/validateClaims.js.map +1 -1
  155. package/esm/options.js +15 -2
  156. package/esm/options.js.map +1 -1
  157. package/esm/server/serverStorage.js +2 -1
  158. package/esm/server/serverStorage.js.map +1 -1
  159. package/esm/tx/AuthTransaction.js +1 -3
  160. package/esm/tx/AuthTransaction.js.map +1 -1
  161. package/esm/tx/api.js +3 -0
  162. package/esm/tx/api.js.map +1 -1
  163. package/esm/types/Transaction.js.map +1 -1
  164. package/esm/util/emailVerify.js +21 -0
  165. package/esm/util/emailVerify.js.map +1 -0
  166. package/esm/util/index.js +1 -0
  167. package/esm/util/index.js.map +1 -1
  168. package/esm/util/sharedStorage.js +43 -0
  169. package/esm/util/sharedStorage.js.map +1 -0
  170. package/lib/AuthStateManager.d.ts +4 -2
  171. package/lib/OktaAuth.d.ts +9 -5
  172. package/lib/StorageManager.d.ts +2 -0
  173. package/lib/TransactionManager.d.ts +5 -1
  174. package/lib/constants.d.ts +2 -0
  175. package/lib/crypto/base64.d.ts +2 -2
  176. package/lib/crypto/oidcHash.d.ts +1 -1
  177. package/lib/crypto/verifyToken.d.ts +1 -1
  178. package/lib/idx/introspect.d.ts +2 -1
  179. package/lib/idx/remediators/Base/AuthenticatorData.d.ts +2 -5
  180. package/lib/idx/remediators/Base/Remediator.d.ts +3 -6
  181. package/lib/idx/remediators/Base/SelectAuthenticator.d.ts +3 -6
  182. package/lib/idx/remediators/Base/VerifyAuthenticator.d.ts +1 -1
  183. package/lib/idx/remediators/EnrollProfile.d.ts +1 -0
  184. package/lib/idx/remediators/Identify.d.ts +1 -5
  185. package/lib/idx/run.d.ts +1 -0
  186. package/lib/idx/transactionMeta.d.ts +4 -3
  187. package/lib/idx/types/idx-js.d.ts +2 -0
  188. package/lib/idx/types/index.d.ts +20 -9
  189. package/lib/oidc/getToken.d.ts +2 -2
  190. package/lib/oidc/parseFromUrl.d.ts +4 -1
  191. package/lib/oidc/renewTokens.d.ts +0 -12
  192. package/lib/oidc/util/loginRedirect.d.ts +1 -1
  193. package/lib/types/AuthState.d.ts +1 -0
  194. package/lib/types/OktaAuthOptions.d.ts +2 -1
  195. package/lib/types/Storage.d.ts +3 -0
  196. package/lib/types/Transaction.d.ts +5 -1
  197. package/lib/types/api.d.ts +9 -4
  198. package/lib/types/http.d.ts +1 -0
  199. package/lib/util/emailVerify.d.ts +17 -0
  200. package/lib/util/index.d.ts +1 -0
  201. package/lib/util/sharedStorage.d.ts +6 -0
  202. package/package.json +12 -10
package/README.md CHANGED
@@ -343,10 +343,9 @@ Depending on your preferences it is possible to use the following callback strat
343
343
  #### Handling the callback with hash routing
344
344
 
345
345
  According to the OAuth 2.0 spec the redirect URI "MUST NOT contain a fragment component": <https://tools.ietf.org/html/rfc6749#section-3.1.2>
346
- So in case of using hash-based `#` strategy and OAuth 2.0, the redirect URI can be defined only like a base url, without any specific route.
347
- That's mean that hash-based router will receive the redirect callback on the main / default route. So we recommend to define the logic that will parse redirect url at the very beginning of your app. So the flow will be similar to [Handling the callback without routing](#handling-the-callback-without-routing)
346
+ When using a hash/fragment routing strategy and OAuth 2.0, the redirect callback will be the main / default route. The redirect callback flow will be very similar to [handling the callback without routing](#handling-the-callback-without-routing). We recommend defining the logic that will parse redirect url at the very beginning of your app, before any other authorization checks.
348
347
 
349
- Additionally if using hash routing, we recommend to use PKCE and responseMode query (which is the default for PKCE). Using implicit flow, with tokens in the hash could cause unpredictable results since hash routers like to rewrite the fragment.
348
+ Additionally, if using hash routing, we recommend using PKCE and responseMode "query" (this is the default for PKCE). With implicit flow, tokens in the hash could cause unpredictable results since hash routers may rewrite the fragment.
350
349
 
351
350
  #### Handling the callback with path routing (on a dedicated route)
352
351
 
@@ -429,11 +428,11 @@ Default value is `true` which enables the [PKCE OAuth Flow](#pkce-oauth-20-flow)
429
428
 
430
429
  #### responseMode
431
430
 
432
- When requesting tokens using [token.getWithRedirect](#tokengetwithredirectoptions) values will be returned as parameters appended to the [redirectUri](#additional-options).
431
+ When requesting tokens using [token.getWithRedirect](#tokengetwithredirectoptions) values will be returned as parameters appended to the [redirectUri](#configuration-options).
433
432
 
434
433
  In most cases you will not need to set a value for `responseMode`. Defaults are set according to the [OpenID Connect 1.0 specification](https://openid.net/specs/openid-connect-core-1_0.html#Authentication).
435
434
 
436
- * For [PKCE OAuth Flow](#pkce-oauth-20-flow)), the authorization code will be in search query of the URL. Clients using the PKCE flow can opt to instead receive the authorization code in the hash fragment by setting the [responseMode](#additional-options) option to "fragment".
435
+ * For [PKCE OAuth Flow](#pkce-oauth-20-flow)), the authorization code will be in search query of the URL. Clients using the PKCE flow can opt to instead receive the authorization code in the hash fragment by setting the [responseMode](#configuration-options) option to "fragment".
437
436
 
438
437
  * For [Implicit OAuth Flow](#implicit-oauth-20-flow)), tokens will be in the hash fragment of the URL. This cannot be changed.
439
438
 
@@ -463,6 +462,11 @@ ID token signatures are validated by default when `token.getWithoutPrompt`, `tok
463
462
 
464
463
  Defaults to 300 (five minutes). This is the maximum difference allowed between a client's clock and Okta's, in seconds, when validating tokens. Setting this to 0 is not recommended, because it increases the likelihood that valid tokens will fail validation.
465
464
 
465
+ #### `ignoreLifetime`
466
+
467
+ Token lifetimes are validated using the `maxClockSkew`.
468
+ To override this and disable token lifetime validation, set this value to `true`.
469
+
466
470
  #### `transformAuthState`
467
471
 
468
472
  Callback function. When [updateAuthState](#authstatemanagerupdateauthstate) is called a new authState object is produced. Providing a `transformAuthState` function allows you to modify or replace this object before it is stored and emitted. A common use case is to change the meaning of [isAuthenticated](#authstatemanager). By default, `updateAuthState` will set `authState.isAuthenticated` to true if unexpired tokens are available from [tokenManager](#tokenmanager). This logic could be customized to also require a valid Okta SSO session:
@@ -508,7 +512,11 @@ const config = {
508
512
 
509
513
  const oktaAuth = new OktaAuth(config);
510
514
  if (oktaAuth.isLoginRedirect()) {
511
- oktaAuth.handleLoginRedirect();
515
+ try {
516
+ await oktaAuth.handleLoginRedirect();
517
+ } catch (e) {
518
+ // log or display error details
519
+ }
512
520
  }
513
521
  ```
514
522
 
@@ -815,24 +823,14 @@ Defaults to `none` if the `secure` option is `true`, or `lax` if the `secure` op
815
823
  * [getAccessToken](#getaccesstoken)
816
824
  * [storeTokensFromRedirect](#storetokensfromredirect)
817
825
  * [setOriginalUri](#setoriginaluriuri)
818
- * [getOriginalUri](#getoriginaluri)
826
+ * [getOriginalUri](#getoriginaluristate)
819
827
  * [removeOriginalUri](#removeoriginaluri)
820
828
  * [isLoginRedirect](#isloginredirect)
821
829
  * [handleLoginRedirect](#handleloginredirecttokens)
830
+ * [setHeaders](#setheaders)
822
831
  * [tx.resume](#txresume)
823
832
  * [tx.exists](#txexists)
824
833
  * [transaction.status](#transactionstatus)
825
- * [LOCKED_OUT](#locked_out)
826
- * [PASSWORD_EXPIRED](#password_expired)
827
- * [PASSWORD_RESET](#password_reset)
828
- * [PASSWORD_WARN](#password_warn)
829
- * [RECOVERY](#recovery)
830
- * [RECOVERY_CHALLENGE](#recovery_challenge)
831
- * [MFA_ENROLL](#mfa_enroll)
832
- * [MFA_ENROLL_ACTIVATE](#mfa_enroll_activate)
833
- * [MFA_REQUIRED](#mfa_required)
834
- * [MFA_CHALLENGE](#mfa_challenge)
835
- * [SUCCESS](#success)
836
834
  * [session](#session)
837
835
  * [session.setCookieAndRedirect](#sessionsetcookieandredirectsessiontoken-redirecturi)
838
836
  * [session.exists](#sessionexists)
@@ -885,41 +883,23 @@ Starts the `OktaAuth` service. See [running as a service](#running-as-a-service)
885
883
 
886
884
  ### `signInWithCredentials(options)`
887
885
 
888
- > :hourglass: async
889
-
890
- The goal of this authentication flow is to [set an Okta session cookie on the user's browser](https://developer.okta.com/use_cases/authentication/session_cookie#retrieving-a-session-cookie-by-visiting-a-session-redirect-link) or [retrieve an `id_token` or `access_token`](https://developer.okta.com/use_cases/authentication/session_cookie#retrieving-a-session-cookie-via-openid-connect-authorization-endpoint). The flow is started using `signInWithCredentials`.
891
-
892
- * `username` - User’s non-qualified short-name (e.g. dade.murphy) or unique fully-qualified login (e.g dade.murphy@example.com)
893
- * `password` - The password of the user
894
- * `sendFingerprint` - Enabling this will send a `X-Device-Fingerprint` header. Defaults to `false`. See [Primary authentication with device fingerprint](https://developer.okta.com/docs/reference/api/authn/#primary-authentication-with-device-fingerprinting) for more information on the `X-Device-Fingerprint` header.
895
-
896
- ```javascript
897
- authClient.signInWithCredentials({
898
- username: 'some-username',
899
- password: 'some-password'
900
- })
901
- .then(function(transaction) {
902
- if (transaction.status === 'SUCCESS') {
903
- authClient.session.setCookieAndRedirect(transaction.sessionToken); // Sets a cookie on redirect
904
- } else {
905
- throw 'We cannot handle the ' + transaction.status + ' status';
906
- }
907
- })
908
- .catch(function(err) {
909
- console.error(err);
910
- });
911
- ```
886
+ See [authn API](docs/authn.md#signinwithcredentials).
912
887
 
913
888
  ### `signInWithRedirect(options)`
914
889
 
915
890
  > :link: web browser only <br>
891
+ > :hourglass: async
916
892
 
917
893
  Starts the full-page redirect to Okta with [optional request parameters](#authorize-options). In this flow, there is a originalUri parameter in options to track the route before the user signIn, and the addtional params are mapped to the [Authorize options](#authorize-options).
918
- You can use [storeTokensFromRedirect](#storetokensfromredirect) to store tokens and [getOriginalUri](#getoriginaluri) to clear the intermediate state (the originalUri) after successful authentication.
894
+ You can use [storeTokensFromRedirect](#storetokensfromredirect) to store tokens and [getOriginalUri](#getoriginaluristate) to clear the intermediate state (the originalUri) after successful authentication.
919
895
 
920
896
  ```javascript
921
897
  if (authClient.isLoginRedirect()) {
922
- await authClient.handleLoginRedirect();
898
+ try {
899
+ await authClient.handleLoginRedirect();
900
+ } catch (e) {
901
+ // log or display error details
902
+ }
923
903
  } else if (!await authClient.isAuthenticated()) {
924
904
  // Start the browser based oidc flow, then parse tokens from the redirect callback url
925
905
  authClient.signInWithRedirect();
@@ -1016,91 +996,15 @@ Revokes the refresh token (if any) for this application so it can no longer be u
1016
996
 
1017
997
  ### `forgotPassword(options)`
1018
998
 
1019
- > :hourglass: async
1020
-
1021
- Starts a [new password recovery transaction](https://developer.okta.com/docs/api/resources/authn#forgot-password) for a given user and issues a recovery token that can be used to reset a user’s password.
1022
-
1023
- * `username` - User’s non-qualified short-name (e.g. dade.murphy) or unique fully-qualified login (e.g dade.murphy@example.com)
1024
- * `factorType` - Recovery factor to use for primary authentication. Supported options are `SMS`, `EMAIL`, or `CALL`
1025
- * `relayState` - Optional state value that is persisted for the lifetime of the recovery transaction
1026
-
1027
- ```javascript
1028
- authClient.forgotPassword({
1029
- username: 'dade.murphy@example.com',
1030
- factorType: 'SMS',
1031
- })
1032
- .then(function(transaction) {
1033
- return transaction.verify({
1034
- passCode: '123456' // The passCode from the SMS or CALL
1035
- });
1036
- })
1037
- .then(function(transaction) {
1038
- if (transaction.status === 'SUCCESS') {
1039
- authClient.session.setCookieAndRedirect(transaction.sessionToken);
1040
- } else {
1041
- throw 'We cannot handle the ' + transaction.status + ' status';
1042
- }
1043
- })
1044
- .catch(function(err) {
1045
- console.error(err);
1046
- });
1047
- ```
999
+ See [authn API](docs/authn.md#forgotpasswordoptions).
1048
1000
 
1049
1001
  ### `unlockAccount(options)`
1050
1002
 
1051
- > :hourglass: async
1052
-
1053
- Starts a [new unlock recovery transaction](https://developer.okta.com/docs/api/resources/authn#unlock-account) for a given user and issues a recovery token that can be used to unlock a user’s account.
1054
-
1055
- * `username` - User’s non-qualified short-name (e.g. dade.murphy) or unique fully-qualified login (e.g dade.murphy@example.com)
1056
- * `factorType` - Recovery factor to use for primary authentication. Supported options are `SMS`, `EMAIL`, or `CALL`
1057
- * `relayState` - Optional state value that is persisted for the lifetime of the recovery transaction
1058
-
1059
- ```javascript
1060
- authClient.unlockAccount({
1061
- username: 'dade.murphy@example.com',
1062
- factorType: 'SMS',
1063
- })
1064
- .then(function(transaction) {
1065
- return transaction.verify({
1066
- passCode: '123456' // The passCode from the SMS
1067
- });
1068
- })
1069
- .then(function(transaction) {
1070
- if (transaction.status === 'SUCCESS') {
1071
- authClient.session.setCookieAndRedirect(transaction.sessionToken);
1072
- } else {
1073
- throw 'We cannot handle the ' + transaction.status + ' status';
1074
- }
1075
- })
1076
- .catch(function(err) {
1077
- console.error(err);
1078
- });
1079
- ```
1003
+ See [authn API](docs/authn.md#unlockaccountoptions).
1080
1004
 
1081
1005
  ### `verifyRecoveryToken(options)`
1082
1006
 
1083
- > :hourglass: async
1084
-
1085
- Validates a recovery token that was distributed to the end-user to continue the [recovery transaction](https://developer.okta.com/docs/api/resources/authn#verify-recovery-token).
1086
-
1087
- * `recoveryToken` - Recovery token that was distributed to end-user via an out-of-band mechanism such as email
1088
-
1089
- ```javascript
1090
- authClient.verifyRecoveryToken({
1091
- recoveryToken: '00xdqXOE5qDZX8-PBR1bYv8AESqIFinDy3yul01tyh'
1092
- })
1093
- .then(function(transaction) {
1094
- if (transaction.status === 'SUCCESS') {
1095
- authClient.session.setCookieAndRedirect(transaction.sessionToken);
1096
- } else {
1097
- throw 'We cannot handle the ' + transaction.status + ' status';
1098
- }
1099
- })
1100
- .catch(function(err) {
1101
- console.error(err);
1102
- });
1103
- ```
1007
+ See [authn API](docs/authn.md#verifyrecoverytokenoptions).
1104
1008
 
1105
1009
  ### `webfinger(options)`
1106
1010
 
@@ -1170,11 +1074,11 @@ Parses tokens from the redirect url and stores them.
1170
1074
 
1171
1075
  ### `setOriginalUri(uri?)`
1172
1076
 
1173
- Stores the current URL state before a redirect occurs. By default it stores `window.location.href`.
1077
+ Stores the current URL state before a redirect occurs.
1174
1078
 
1175
- ### `getOriginalUri()`
1079
+ ### `getOriginalUri(state?)`
1176
1080
 
1177
- Returns the stored URI string stored by [setOriginal](#setoriginaluriuri). By default it returns `window.location.origin`.
1081
+ Returns the stored URI string stored by [setOriginal](#setoriginaluriuri). An OAuth `state` parameter is optional. If no value is passed for `state`, the URI is retrieved from isolated session storage and will work in a single browser. If a valid OAuth `state` is passed this method can return the URI stored from another browser tab.
1178
1082
 
1179
1083
  ### `removeOriginalUri()`
1180
1084
 
@@ -1189,886 +1093,67 @@ Check `window.location` to verify if the app is in OAuth callback state or not.
1189
1093
  ```javascript
1190
1094
  if (authClient.isLoginRedirect()) {
1191
1095
  // callback flow
1192
- await authClient.handleLoginRedirect();
1096
+ try {
1097
+ await authClient.handleLoginRedirect();
1098
+ } catch (e) {
1099
+ // log or display error details
1100
+ }
1193
1101
  } else {
1194
1102
  // normal app flow
1195
1103
  }
1196
1104
  ```
1197
1105
 
1198
- ### `handleLoginRedirect(tokens?)`
1106
+ ### `handleLoginRedirect(tokens?, originalUri?)`
1199
1107
 
1200
1108
  > :link: web browser only <br>
1201
-
1202
- Stores passed in tokens or tokens from redirect url into storage, then redirect users back to the [originalUri](#setoriginaluriuri). By default it calls `window.location.replace` for the redirection. The default behavior can be overrided by providing [options.restoreOriginalUri](#additional-options).
1203
-
1204
- ### `tx.resume()`
1205
-
1206
- > :hourglass: async
1207
-
1208
- Resumes an in-progress **transaction**. This is useful if a user navigates away from the login page before authentication is complete.
1209
-
1210
- ```javascript
1211
- var exists = authClient.tx.exists();
1212
- if (exists) {
1213
- authClient.tx.resume()
1214
- .then(function(transaction) {
1215
- console.log('current status:', transaction.status);
1216
- })
1217
- .catch(function(err) {
1218
- console.error(err);
1219
- });
1220
- }
1221
- ```
1222
-
1223
- ### `tx.exists()`
1224
-
1225
- Check for a **transaction** to be resumed. This is synchronous and returns `true` or `false`.
1226
-
1227
- ```javascript
1228
- var exists = authClient.tx.exists();
1229
- if (exists) {
1230
- console.log('a session exists');
1231
- } else {
1232
- console.log('a session does not exist');
1233
- }
1234
- ```
1235
-
1236
- ### `transaction.status`
1237
-
1238
- > :hourglass: async
1239
-
1240
- When Auth Client methods resolve, they return a **transaction** object that encapsulates [the new state in the authentication flow](https://developer.okta.com/docs/reference/api/authn/#transaction-state). This **transaction** contains metadata about the current state, and methods that can be used to progress to the next state.
1241
-
1242
- ![State Model Diagram](https://developer.okta.com/img/auth-state-model.png "State Model Diagram")
1243
-
1244
- #### Common methods
1245
-
1246
- ##### `cancel()`
1247
-
1248
1109
  > :hourglass: async
1249
- Terminates the current auth flow.
1250
-
1251
- ```javascript
1252
- transaction.cancel()
1253
- .then(function() {
1254
- // transaction canceled. You can now start another with authClient.signIn
1255
- });
1256
- ```
1257
-
1258
- ##### `changePassword(options)`
1259
-
1260
- [Changes](https://developer.okta.com/docs/api/resources/authn#reset-password) a user's password.
1261
-
1262
- * `oldPassword` - User’s current password that is expired
1263
- * `newPassword` - New password for user
1264
-
1265
- ```javascript
1266
- transaction.changePassword({
1267
- oldPassword: '0ldP4ssw0rd',
1268
- newPassword: 'N3wP4ssw0rd'
1269
- });
1270
- ```
1271
-
1272
- ##### `resetPassword(options)`
1273
-
1274
- [Reset](https://developer.okta.com/docs/api/resources/authn#reset-password) a user's password.
1275
-
1276
- * `newPassword` - New password for user
1277
-
1278
- ```javascript
1279
- transaction.resetPassword({
1280
- newPassword: 'N3wP4ssw0rd'
1281
- });
1282
- ```
1283
-
1284
- ##### `skip()`
1285
-
1286
- Ignore the warning and continue.
1287
-
1288
- ```javascript
1289
- transaction.skip();
1290
- ```
1291
-
1292
- #### LOCKED_OUT
1293
-
1294
- The user account is [locked](https://developer.okta.com/docs/api/resources/authn#show-lockout-failures); self-service unlock or admin unlock is required.
1295
-
1296
- <details>
1297
- <summary><b>Example Response</b></summary>
1298
-
1299
- ```javascript
1300
- {
1301
- status: 'LOCKED_OUT',
1302
- unlock: function(options) { /* returns another transaction */ },
1303
- cancel: function() { /* terminates the auth flow */ },
1304
- data: { /* the parsed json response */ }
1305
- }
1306
- ```
1307
-
1308
- </details>
1309
-
1310
- ##### `unlock(options)`
1311
-
1312
- [Unlock](https://developer.okta.com/docs/api/resources/authn#unlock-account) the user account.
1313
-
1314
- * `username` - User’s non-qualified short-name (e.g. dade.murphy) or unique fully-qualified login (e.g dade.murphy@example.com)
1315
- * `factorType` - Recovery factor to use for primary authentication. Supported options are `SMS`, `EMAIL`, or `CALL`
1316
- * `relayState` - Optional state value that is persisted for the lifetime of the recovery transaction
1317
1110
 
1318
- ```javascript
1319
- transaction.unlock({
1320
- username: 'dade.murphy@example.com',
1321
- factorType: 'EMAIL'
1322
- });
1323
- ```
1324
-
1325
- #### PASSWORD_EXPIRED
1326
-
1327
- The user’s password was successfully validated but is [expired](https://developer.okta.com/docs/api/resources/authn#response-example-expired-password).
1328
-
1329
- <details>
1330
- <summary><b>Example Response</b></summary>
1331
-
1332
- ```javascript
1333
- {
1334
- status: 'PASSWORD_EXPIRED',
1335
- expiresAt: '2014-11-02T23:39:03.319Z',
1336
- user: {
1337
- id: '00ub0oNGTSWTBKOLGLNR',
1338
- profile: {
1339
- login: 'isaac@example.org',
1340
- firstName: 'Isaac',
1341
- lastName: 'Brock',
1342
- locale: 'en_US',
1343
- timeZone: 'America/Los_Angeles'
1344
- }
1345
- },
1346
- changePassword: function(options) { /* returns another transaction */ },
1347
- cancel: function() { /* terminates the auth flow */ },
1348
- data: { /* the parsed json response */ }
1349
- }
1350
- ```
1351
-
1352
- </details>
1353
-
1354
- #### PASSWORD_RESET
1355
-
1356
- The user successfully answered their recovery question and can set a new password.
1357
-
1358
- <details>
1359
- <summary><b>Example Response</b></summary>
1360
-
1361
- ```javascript
1362
- {
1363
- status: 'PASSWORD_EXPIRED',
1364
- expiresAt: '2014-11-02T23:39:03.319Z',
1365
- user: {
1366
- id: '00ub0oNGTSWTBKOLGLNR',
1367
- profile: {
1368
- login: 'isaac@example.org',
1369
- firstName: 'Isaac',
1370
- lastName: 'Brock',
1371
- locale: 'en_US',
1372
- timeZone: 'America/Los_Angeles'
1373
- }
1374
- },
1375
- resetPassword: function(options) { /* returns another transaction */ },
1376
- cancel: function() { /* terminates the auth flow */ },
1377
- data: { /* the parsed json response */ }
1378
- }
1379
- ```
1111
+ Stores passed in tokens or tokens from redirect url into storage, then redirect users back to the [originalUri](#setoriginaluriuri). When using `PKCE` authorization code flow, this method also exchanges authorization code for tokens. By default it calls `window.location.replace` for the redirection. The default behavior can be overrided by providing [options.restoreOriginalUri](#configuration-options). By default, [originalUri](#getoriginaluristate) will be retrieved from storage, but this can be overridden by passing a value fro `originalUri` to this function in the 2nd parameter.
1380
1112
 
1381
- </details>
1113
+ > **Note:** `handleLoginRedirect` throws `OAuthError` or `AuthSdkError` in case there are errors during token retrieval.
1382
1114
 
1383
- #### PASSWORD_WARN
1115
+ ### `setHeaders()`
1384
1116
 
1385
- The user’s password was successfully validated but is about to expire and should be changed.
1386
-
1387
- <details>
1388
- <summary><b>Example Response</b></summary>
1389
-
1390
- ```javascript
1391
- {
1392
- status: 'PASSWORD_WARN',
1393
- expiresAt: '2014-11-02T23:39:03.319Z',
1394
- user: {
1395
- id: '00ub0oNGTSWTBKOLGLNR',
1396
- profile: {
1397
- login: 'isaac@example.org',
1398
- firstName: 'Isaac',
1399
- lastName: 'Brock',
1400
- locale: 'en_US',
1401
- timeZone: 'America/Los_Angeles'
1402
- }
1403
- },
1404
- policy: {
1405
- expiration:{
1406
- passwordExpireDays: 0
1407
- },
1408
- complexity: {
1409
- minLength: 8,
1410
- minLowerCase: 1,
1411
- minUpperCase: 1,
1412
- minNumber: 1,
1413
- minSymbol: 0,
1414
- excludeUsername: true
1415
- },
1416
- age:{
1417
- minAgeMinutes:0,
1418
- historyCount:0
1419
- }
1420
- },
1421
- changePassword: function(options) { /* returns another transaction */ },
1422
- skip: function() { /* returns another transaction */ },
1423
- cancel: function() { /* terminates the auth flow */ },
1424
- data: { /* the parsed json response */ }
1425
- }
1426
- ```
1427
-
1428
- </details>
1429
-
1430
- #### RECOVERY
1431
-
1432
- The user has requested a recovery token to reset their password or unlock their account.
1433
-
1434
- <details>
1435
- <summary><b>Example Response</b></summary>
1436
-
1437
- ```javascript
1438
- {
1439
- status: 'RECOVERY',
1440
- expiresAt: '2014-11-02T23:39:03.319Z',
1441
- recoveryType: 'PASSWORD', // or 'UNLOCK'
1442
- user: {
1443
- id: '00ub0oNGTSWTBKOLGLNR',
1444
- profile: {
1445
- login: 'isaac@example.org',
1446
- firstName: 'Isaac',
1447
- lastName: 'Brock',
1448
- locale: 'en_US',
1449
- timeZone: 'America/Los_Angeles'
1450
- },
1451
- recovery_question: {
1452
- question: "Who's a major player in the cowboy scene?"
1453
- }
1454
- },
1455
- answer: function(options) { /* returns another transaction */ },
1456
- recovery: function(options) { /* returns another transaction */ },
1457
- cancel: function() { /* terminates the auth flow */ },
1458
- data: { /* the parsed json response */ }
1459
- }
1460
- ```
1461
-
1462
- </details>
1463
-
1464
- ##### `answer(options)`
1465
-
1466
- * `answer` - [Answer](https://developer.okta.com/docs/api/resources/authn#answer-recovery-question) to user’s recovery question
1117
+ Can set (or unset) request headers after construction.
1467
1118
 
1468
1119
  ```javascript
1469
- transaction.answer({
1470
- answer: 'My favorite recovery question answer'
1471
- });
1472
- ```
1473
-
1474
- ##### `recovery(options)`
1475
-
1476
- * `recoveryToken` - [Recovery](https://developer.okta.com/docs/api/resources/authn#verify-recovery-token) token that was distributed to end-user via out-of-band mechanism such as email
1477
-
1478
- ```javascript
1479
- transaction.recovery({
1480
- recoveryToken: '00xdqXOE5qDZX8-PBR1bYv8AESqIFinDy3yul01tyh'
1481
- });
1482
- ```
1483
-
1484
- #### RECOVERY_CHALLENGE
1485
-
1486
- The user must verify the factor-specific recovery challenge.
1487
-
1488
- <details>
1489
- <summary><b>Example Response</b></summary>
1490
-
1491
- ```javascript
1492
- {
1493
- status: 'RECOVERY_CHALLENGE',
1494
- expiresAt: '2014-11-02T23:39:03.319Z',
1495
- recoveryType: 'PASSWORD', // or 'UNLOCK',
1496
- factorType: 'EMAIL', // or 'SMS'
1497
- user: {
1498
- id: '00ub0oNGTSWTBKOLGLNR',
1499
- profile: {
1500
- login: 'isaac@example.org',
1501
- firstName: 'Isaac',
1502
- lastName: 'Brock',
1503
- locale: 'en_US',
1504
- timeZone: 'America/Los_Angeles'
1505
- }
1506
- },
1507
- verify: function(options) { /* returns another transaction */ },
1508
- resend: function() { /* returns another transaction */ },
1509
- cancel: function() { /* terminates the auth flow */ },
1510
- data: { /* the parsed json response */ }
1511
- }
1512
- ```
1513
-
1514
- </details>
1515
-
1516
- ##### `verify(options)`
1517
-
1518
- * `passCode` - OTP sent to device for [verification](https://developer.okta.com/docs/api/resources/authn#verify-sms-recovery-factor)
1519
-
1520
- ```javascript
1521
- transaction.verify({
1522
- passCode: '615243'
1523
- });
1524
- ```
1525
-
1526
- ##### `resend()`
1527
-
1528
- [Resend](https://developer.okta.com/docs/api/resources/authn#resend-sms-recovery-challenge) the recovery email or text.
1529
-
1530
- ```javascript
1531
- transaction.resend();
1532
- ```
1533
-
1534
- #### MFA_ENROLL
1535
-
1536
- When MFA is required, but a user isn’t enrolled in MFA, they must enroll in at least one factor.
1537
-
1538
- <details>
1539
- <summary><b>Example Response</b></summary>
1540
-
1541
- ```javascript
1542
- {
1543
- status: 'MFA_ENROLL',
1544
- expiresAt: '2014-11-02T23:39:03.319Z',
1545
- user: {
1546
- id: '00ub0oNGTSWTBKOLGLNR',
1547
- profile: {
1548
- login: 'isaac@example.org',
1549
- firstName: 'Isaac',
1550
- lastName: 'Brock',
1551
- locale: 'en_US',
1552
- timeZone: 'America/Los_Angeles'
1553
- }
1554
- },
1555
- factors: [{
1556
- provider: 'OKTA',
1557
- factorType: 'question',
1558
- questions: function() { /* returns an array of possible questions */ },
1559
- enroll: function(options) { /* returns another transaction */ }
1560
- }, {
1561
- provider: 'OKTA',
1562
- factorType: 'sms',
1563
- enroll: function(options) { /* returns another transaction */ }
1564
- }, {
1565
- provider: 'OKTA',
1566
- factorType: 'call',
1567
- enroll: function(options) { /* returns another transaction */ }
1568
- }, {
1569
- provider: 'OKTA',
1570
- factorType: 'push',
1571
- enroll: function(options) { /* returns another transaction */ }
1572
- }, {
1573
- provider: 'OKTA',
1574
- factorType: 'token:software:totp',
1575
- enroll: function(options) { /* returns another transaction */ }
1576
- }, {
1577
- provider: 'GOOGLE',
1578
- factorType: 'token:software:totp',
1579
- enroll: function(options) { /* returns another transaction */ }
1580
- }, {
1581
- provider: 'YUBICO',
1582
- factorType: 'token:hardware',
1583
- enroll: function(options) { /* returns another transaction */ }
1584
- }, {
1585
- provider: 'RSA',
1586
- factorType: 'token',
1587
- enroll: function(options) { /* returns another transaction */ }
1588
- }, {
1589
- provider: 'SYMANTEC',
1590
- factorType: 'token',
1591
- enroll: function(options) { /* returns another transaction */ }
1592
- }],
1593
- cancel: function() { /* terminates the auth flow */ },
1594
- data: { /* the parsed json response */ }
1595
- }
1596
- ```
1597
-
1598
- </details>
1599
-
1600
- To enroll in a factor, select one from the factors array, then use the following methods.
1601
-
1602
- ```javascript
1603
- var factor = transaction.factors[/* index of the desired factor */];
1604
- ```
1605
-
1606
- ##### `questions()`
1607
-
1608
- List the available [questions](https://developer.okta.com/docs/api/resources/factors#list-security-questions) for the question factorType.
1609
-
1610
- ```javascript
1611
- var questionFactor = transaction.factors.find(function(factor) {
1612
- return factor.provider === 'OKTA' && factor.factorType === 'question';
1613
- });
1614
-
1615
- questionFactor.questions()
1616
- .then(function(questions) {
1617
- // Display questions for the user to select from
1618
- });
1619
- ```
1620
-
1621
- ##### `enroll(options)`
1622
-
1623
- The enroll options depend on the desired factor.
1624
-
1625
- ###### [OKTA question](https://developer.okta.com/docs/api/resources/factors#enroll-okta-security-question-factor)
1626
-
1627
- ```javascript
1628
- var questionFactor = transaction.factors.find(function(factor) {
1629
- return factor.provider === 'OKTA' && factor.factorType === 'question';
1630
- });
1631
-
1632
- questionFactor.enroll({
1633
- profile: {
1634
- question: 'disliked_food', // all questions available using questionFactor.questions()
1635
- answer: 'mayonnaise'
1636
- }
1637
- });
1638
- ```
1639
-
1640
- ###### [OKTA sms](https://developer.okta.com/docs/api/resources/factors#enroll-okta-sms-factor)
1641
-
1642
- ```javascript
1643
- var factor = transaction.factors.find(function(factor) {
1644
- return factor.provider === 'OKTA' && factor.factorType === 'sms';
1645
- });
1646
-
1647
- factor.enroll({
1648
- profile: {
1649
- phoneNumber: '+1-555-415-1337',
1650
- updatePhone: true
1651
- }
1652
- });
1653
-
1654
- // The passCode sent to the phone is verified in MFA_ENROLL_ACTIVATE
1655
- ```
1656
-
1657
- ###### [OKTA call](https://developer.okta.com/docs/api/resources/factors#enroll-okta-call-factor)
1658
-
1659
- ```javascript
1660
- var factor = transaction.factors.find(function(factor) {
1661
- return factor.provider === 'OKTA' && factor.factorType === 'call';
1662
- });
1663
-
1664
- factor.enroll({
1665
- profile: {
1666
- phoneNumber: '+1-555-415-1337',
1667
- updatePhone: true
1668
- }
1669
- });
1670
-
1671
- // The passCode from the call is verified in MFA_ENROLL_ACTIVATE
1672
- ```
1673
-
1674
- ###### [OKTA push](https://developer.okta.com/docs/api/resources/factors#enroll-okta-verify-push-factor)
1675
-
1676
- ```javascript
1677
- var factor = transaction.factors.find(function(factor) {
1678
- return factor.provider === 'OKTA' && factor.factorType === 'push';
1679
- });
1680
-
1681
- factor.enroll();
1682
-
1683
- // The phone will need to scan a QR Code in MFA_ENROLL_ACTIVATE
1684
- ```
1685
-
1686
- ###### [OKTA token:software:totp](https://developer.okta.com/docs/api/resources/factors#enroll-okta-verify-totp-factor)
1687
-
1688
- ```javascript
1689
- var factor = transaction.factors.find(function(factor) {
1690
- return factor.provider === 'OKTA' && factor.factorType === 'token:software:totp';
1691
- });
1692
-
1693
- factor.enroll();
1694
-
1695
- // The phone will need to scan a QR Code in MFA_ENROLL_ACTIVATE
1696
- ```
1697
-
1698
- ###### [GOOGLE token:software:totp](https://developer.okta.com/docs/api/resources/factors#enroll-google-authenticator-factor)
1699
-
1700
- ```javascript
1701
- var factor = transaction.factors.find(function(factor) {
1702
- return factor.provider === 'GOOGLE' && factor.factorType === 'token:software:totp';
1703
- });
1704
-
1705
- factor.enroll();
1706
-
1707
- // The phone will need to scan a QR Code in MFA_ENROLL_ACTIVATE
1708
- ```
1709
-
1710
- ###### [YUBICO token:hardware](https://developer.okta.com/docs/api/resources/factors#enroll-yubikey-factor)
1711
-
1712
- ```javascript
1713
- var factor = transaction.factors.find(function(factor) {
1714
- return factor.provider === 'YUBICO' && factor.factorType === 'token:hardware';
1715
- });
1716
-
1717
- factor.enroll({
1718
- passCode: 'cccccceukngdfgkukfctkcvfidnetljjiknckkcjulji'
1719
- });
1720
- ```
1721
-
1722
- ###### [RSA token](https://developer.okta.com/docs/api/resources/factors#enroll-rsa-securid-factor)
1723
-
1724
- ```javascript
1725
- var factor = transaction.factors.find(function(factor) {
1726
- return factor.provider === 'RSA' && factor.factorType === 'token';
1727
- });
1728
-
1729
- factor.enroll({
1730
- passCode: '5275875498',
1731
- profile: {
1732
- credentialId: 'dade.murphy@example.com'
1733
- }
1734
- });
1735
- ```
1736
-
1737
- ###### [SYMANTEC token](https://developer.okta.com/docs/api/resources/factors#enroll-symantec-vip-factor)
1738
-
1739
- ```javascript
1740
- var factor = transaction.factors.find(function(factor) {
1741
- return factor.provider === 'SYMANTEC' && factor.factorType === 'token';
1742
- });
1743
-
1744
- factor.enroll({
1745
- passCode: '875498',
1746
- nextPassCode: '678195',
1747
- profile: {
1748
- credentialId: 'VSMT14393584'
1749
- }
1750
- });
1751
- ```
1752
-
1753
- #### MFA_ENROLL_ACTIVATE
1754
-
1755
- The user must activate the factor to complete enrollment.
1756
-
1757
- <details>
1758
- <summary><b>Example Response</b></summary>
1759
-
1760
- ```javascript
1761
- {
1762
- status: 'MFA_ENROLL_ACTIVATE',
1763
- expiresAt: '2014-11-02T23:39:03.319Z',
1764
- factorResult: 'WAITING', // or 'TIMEOUT',
1765
- user: {
1766
- id: '00ugti3kwafWJBRIY0g3',
1767
- profile: {
1768
- login: 'isaac@example.org',
1769
- firstName: 'Isaac',
1770
- lastName: 'Brock',
1771
- locale: 'en_US',
1772
- timeZone: 'America/Los_Angeles'
1773
- },
1774
- },
1775
- factor: {
1776
- id: 'opfh52xcuft3J4uZc0g3',
1777
- provider: 'OKTA',
1778
- factorType: 'push',
1779
- profile: {},
1780
- activation: {
1781
- expiresAt: '2015-04-01T15:57:32.000Z',
1782
- qrcode: {
1783
- href: 'https://acme.okta.com/api/v1/users/00ugti3kwafWJBRIY0g3/factors/opfh52xcuft3J4uZc0g3/qr/00fukNElRS_Tz6k-CFhg3pH4KO2dj2guhmaapXWbc4',
1784
- type: 'image/png'
1785
- }
1786
- }
1787
- },
1788
- resend: function() { /* returns another transaction */ },
1789
- activate: function(options) { /* returns another transaction */ },
1790
- poll: function() { /* returns another transaction */ },
1791
- prev: function() { /* returns another transaction */ },
1792
- cancel: function() { /* terminates the auth flow */ },
1793
- data: { /* the parsed json response */ }
1794
- }
1795
- ```
1796
-
1797
- </details>
1798
-
1799
- ##### `resend()`
1800
-
1801
- Send another OTP if user doesn’t receive the original activation SMS OTP.
1802
-
1803
- ```javascript
1804
- transaction.resend();
1805
- ```
1806
-
1807
- ##### `activate(options)`
1808
-
1809
- * `passCode` - OTP- sent to device for [activation](https://developer.okta.com/docs/api/resources/authn#activate-sms-factor)
1810
-
1811
- ```javascript
1812
- transaction.activate({
1813
- passCode: '615243'
1814
- });
1815
- ```
1816
-
1817
- ##### `poll()`
1818
-
1819
- [Poll](https://developer.okta.com/docs/api/resources/authn#activate-push-factor) until factorResult is not WAITING. Throws AuthPollStopError if prev, resend, or cancel is called.
1820
-
1821
- ```javascript
1822
- transaction.poll();
1823
- ```
1824
-
1825
- ##### `prev()`
1826
-
1827
- End current factor enrollment and [return to](https://developer.okta.com/docs/api/resources/authn#previous-transaction-state) `MFA_ENROLL`.
1828
-
1829
- ```javascript
1830
- transaction.prev();
1831
- ```
1832
-
1833
- #### MFA_REQUIRED
1834
-
1835
- The user must provide additional verification with a previously enrolled factor.
1836
- <details>
1837
- <summary> <b>Example Response</b> </summary>
1120
+ const authClient = new OktaAuth({
1121
+ issuer: 'https://{yourOktaDomain}',
1838
1122
 
1839
- ```javascript
1840
- {
1841
- status: 'MFA_REQUIRED',
1842
- expiresAt: '2014-11-02T23:39:03.319Z',
1843
- user: {
1844
- id: '00ugti3kwafWJBRIY0g3',
1845
- profile: {
1846
- login: 'isaac@example.org',
1847
- firstName: 'Isaac',
1848
- lastName: 'Brock',
1849
- locale: 'en_US',
1850
- timeZone: 'America/Los_Angeles'
1851
- },
1852
- },
1853
- factors: [{
1854
- id: 'ufsigasO4dVUPM5O40g3',
1855
- provider: 'OKTA',
1856
- factorType: 'question',
1857
- profile: {
1858
- question: 'disliked_food',
1859
- questionText: 'What is the food you least liked as a child?'
1860
- },
1861
- verify: function(options) { /* returns another transaction */ }
1862
- }, {
1863
- id: 'opfhw7v2OnxKpftO40g3',
1864
- provider: 'OKTA',
1865
- factorType: 'push',
1866
- profile: {
1867
- credentialId: 'isaac@example.org',
1868
- deviceType: 'SmartPhone_IPhone',
1869
- keys: [
1870
- {
1871
- kty: 'PKIX',
1872
- use: 'sig',
1873
- kid: 'default',
1874
- x5c: [
1875
- 'MIIBIjANBgkqhkiG9w0BAQEFBAOCAQ8AMIIBCgKCAQEAs4LfXaaQW6uIpkjoiKn2g9B6nNQDraLyC3XgHP5cvX/qaqry43SwyqjbQtwRkScosDHl59r0DX1V/3xBtBYwdo8rAdX3I5h6z8lW12xGjOkmb20TuAiy8wSmzchdm52kWodUb7OkMk6CgRJRSDVbC97eNcfKk0wmpxnCJWhC+AiSzRVmgkpgp8NanuMcpI/X+W5qeqWO0w3DGzv43FkrYtfSkvpDdO4EvDL8bWX1Ad7mBoNVLWErcNf/uI+r/jFpKHgjvx3iqs2Q7vcfY706Py1m91vT0vs4SWXwzVV6pAVjD/kumL+nXfzfzAHw+A2vb6J2w06Rj71bqUkC2b8TpQIDAQAB'
1876
- ]
1877
- }
1878
- ],
1879
- name: 'Isaac\'s iPhone',
1880
- platform: 'IOS',
1881
- version: '8.1.3'
1882
- },
1883
- verify: function() { /* returns another transaction */ }
1884
- }, {
1885
- id: 'smsigwDlH85L9FyQK0g3',
1886
- provider: 'OKTA',
1887
- factorType: 'sms',
1888
- profile: {
1889
- phoneNumber: '+1 XXX-XXX-3355'
1890
- },
1891
- verify: function() { /* returns another transaction */ }
1892
- }, {
1893
- id: 'ostigevBq2NObXmTh0g3',
1894
- provider: 'OKTA',
1895
- factorType: 'token:software:totp',
1896
- profile: {
1897
- credentialId: 'isaac@example.org'
1898
- },
1899
- verify: function() { /* returns another transaction */ }
1900
- }, {
1901
- id: 'uftigiEmYTPOmvqTS0g3',
1902
- provider: 'GOOGLE',
1903
- factorType: 'token:software:totp',
1904
- profile: {
1905
- credentialId: 'isaac@example.org'
1906
- },
1907
- verify: function() { /* returns another transaction */ }
1908
- }],
1909
- cancel: function() { /* terminates the auth flow */ },
1910
- data: { /* the parsed json response */ }
1123
+ // headers can be set during construction
1124
+ headers: {
1125
+ foo: 'bar'
1911
1126
  }
1912
- ```
1913
-
1914
- </details>
1915
-
1916
- ##### [Verify Factor](https://developer.okta.com/docs/api/resources/authn#verify-factor)
1917
-
1918
- To verify a factor, select one from the factors array, then use the following methods.
1919
-
1920
- ```javascript
1921
- var factor = transaction.factors[/* index of the desired factor */];
1922
- ```
1923
-
1924
- ###### [OKTA question](https://developer.okta.com/docs/api/resources/authn#verify-security-question-factor)
1925
-
1926
- ```javascript
1927
- var questionFactor = transaction.factors.find(function(factor) {
1928
- return factor.provider === 'OKTA' && factor.factorType === 'question';
1929
1127
  });
1930
1128
 
1931
- questionFactor.verify({
1932
- answer: 'mayonnaise'
1129
+ // Headers can be set (or modified) after construction
1130
+ authClient.setHeaders({
1131
+ foo: 'baz'
1933
1132
  });
1934
- ```
1935
-
1936
- ###### [OKTA push](https://developer.okta.com/docs/api/resources/authn#verify-push-factor)
1937
1133
 
1938
- * `autoPush` - Optional parameter to send a push notification immediately the next time `verify` is called on a push factor
1939
-
1940
- ```javascript
1941
- var pushFactor = transaction.factors.find(function(factor) {
1942
- return factor.provider === 'OKTA' && factor.factorType === 'push';
1943
- });
1944
-
1945
- pushFactor.verify({
1946
- autoPush: true
1947
- });
1948
- ```
1949
-
1950
- ###### [All other factors](https://developer.okta.com/docs/api/resources/authn#verify-factor)
1951
-
1952
- ```javascript
1953
- var factor = transaction.factors.find(function(factor) {
1954
- return factor.provider === 'YOUR_PROVIDER' && factor.factorType === 'yourFactorType';
1955
- });
1956
-
1957
- factor.verify();
1958
- ```
1959
-
1960
- #### MFA_CHALLENGE
1961
-
1962
- The user must verify the factor-specific challenge.
1963
- <details>
1964
- <summary><b>Example Response</b></summary>
1965
-
1966
- ```javascript
1967
- {
1968
- status: 'MFA_CHALLENGE',
1969
- expiresAt: '2014-11-02T23:39:03.319Z',
1970
- factorResult: 'WAITING', // or CANCELLED, TIMEOUT, or ERROR
1971
- user: {
1972
- id: '00ugti3kwafWJBRIY0g3',
1973
- profile: {
1974
- login: 'isaac@example.org',
1975
- firstName: 'Isaac',
1976
- lastName: 'Brock',
1977
- locale: 'en_US',
1978
- timeZone: 'America/Los_Angeles'
1979
- },
1980
- },
1981
- factor: {
1982
- id: 'smsigwDlH85L9FyQK0g3',
1983
- factorType: 'sms',
1984
- provider: 'OKTA',
1985
- profile: {
1986
- phoneNumber: '+1 XXX-XXX-6688'
1987
- }
1988
- },
1989
- verify: function(options) { /* returns another transaction */ },
1990
- poll: function() { /* returns another transaction */ },
1991
- prev: function() { /* returns another transaction */ },
1992
- cancel: function() { /* terminates the auth flow */ },
1993
- data: { /* the parsed json response */ }
1994
- }
1995
- ```
1996
-
1997
- </details>
1998
-
1999
- ##### `verify(options)`
2000
-
2001
- * `passCode` - OTP sent to device
2002
- * `autoPush` - Optional parameter to send a push notification immediately the next time [`verify`](https://developer.okta.com/docs/api/resources/authn#verify-factor) is called on a push factor
2003
-
2004
- ```javascript
2005
- transaction.verify({
2006
- passCode: '615243',
2007
- autoPush: true
2008
- });
2009
- ```
2010
-
2011
- ##### `poll(options)`
2012
-
2013
- * `autoPush` - Optional parameter to send a push notification immediately the next time `verify` is called on a push factor
2014
-
2015
- [Poll](https://developer.okta.com/docs/api/resources/authn#activate-push-factor) until factorResult is not WAITING. Throws AuthPollStopError if prev, resend, or cancel is called.
2016
-
2017
- ```javascript
2018
- transaction.poll({
2019
- autoPush: true
2020
- });
1134
+ // Headers can be removed
1135
+ authClient.setHeaders({
1136
+ foo: undefined
1137
+ })
2021
1138
  ```
2022
1139
 
2023
- ##### `prev()`
2024
-
2025
- End current factor verification and [return to](https://developer.okta.com/docs/api/resources/authn#previous-transaction-state) `MFA_REQUIRED`.
2026
-
2027
- ```javascript
2028
- transaction.prev();
2029
- ```
1140
+ ### `tx.resume()`
2030
1141
 
2031
- #### SUCCESS
1142
+ See [authn API](docs/authn.md#txresume).
2032
1143
 
2033
- The end of the authentication flow! This transaction contains a sessionToken you can exchange for an Okta cookie, an `id_token`, or `access_token`.
1144
+ ### `tx.exists()`
2034
1145
 
2035
- <details>
2036
- <summary><b>Example Response</b></summary>
1146
+ See [authn API](docs/authn.md#txexists).
2037
1147
 
2038
- ```javascript
2039
- {
2040
- expiresAt: '2015-06-08T23:34:34.000Z',
2041
- status: 'SUCCESS',
2042
- sessionToken: '00p8RhRDCh_8NxIin-wtF5M6ofFtRhfKWGBAbd2WmE',
2043
- user: {
2044
- id: '00uhm5QzwyZZxjrfp0g3',
2045
- profile: {
2046
- login: 'exampleUser@example.com',
2047
- firstName: 'Test',
2048
- lastName: 'User',
2049
- locale: 'en_US',
2050
- timeZone: 'America/Los_Angeles'
2051
- }
2052
- }
2053
- }
2054
- ```
1148
+ ### `transaction.status`
2055
1149
 
2056
- </details>
1150
+ See [authn API](docs/authn.md#transactionstatus).
2057
1151
 
2058
1152
  ### `session`
2059
1153
 
2060
1154
  #### `session.setCookieAndRedirect(sessionToken, redirectUri)`
2061
1155
 
2062
- > :link: web browser only <br>
2063
- > :warning: method requires access to [third party cookies] <br>(#third-party-cookies)
2064
-
2065
- This allows you to create a session using a sessionToken.
2066
- * `sessionToken` - Ephemeral one-time token used to bootstrap an Okta session.
2067
- * `redirectUri` - After setting a cookie, Okta redirects to the specified URI. The default is the current URI.
2068
-
2069
- ```javascript
2070
- authClient.session.setCookieAndRedirect(transaction.sessionToken);
2071
- ```
1156
+ See [authn API](docs/authn.md#sessionsetcookieandredirectsessiontoken-redirecturi).
2072
1157
 
2073
1158
  #### `session.exists()`
2074
1159
 
@@ -2230,7 +1315,7 @@ authClient.token.getWithPopup(options)
2230
1315
  > :link: web browser only <br>
2231
1316
  > :hourglass: async
2232
1317
 
2233
- Create token using a redirect. After a successful authentication, the browser will be redirected to the configured [redirectUri](#additional-options). The authorization code, access, or ID Tokens will be available as parameters appended to this URL. Values will be returned in either the search query or hash fragment portion of the URL depending on the [responseMode](#responsemode)
1318
+ Create token using a redirect. After a successful authentication, the browser will be redirected to the configured [redirectUri](#configuration-options). The authorization code, access, or ID Tokens will be available as parameters appended to this URL. Values will be returned in either the search query or hash fragment portion of the URL depending on the [responseMode](#responsemode)
2234
1319
 
2235
1320
  * `options` - See [Authorize options](#authorize-options)
2236
1321
 
@@ -2275,7 +1360,7 @@ authClient.token.parseFromUrl()
2275
1360
  });
2276
1361
  ```
2277
1362
 
2278
- After reading values, this method will rewrite either the hash fragment or search query portion of the URL (depending on the [responseMode](#responsemode)) so that the code or tokens are no longer present or visible to the user. For this reason, it is recommended to use a dedicated route or path for the [redirectUri](#additional-options) so that this URL rewrite does not interfere with other URL parameters which may be used by your application. A complete login flow will usually save the current URL before calling `getWithRedirect` and restore the URL after saving tokens from `parseFromUrl`.
1363
+ After reading values, this method will rewrite either the hash fragment or search query portion of the URL (depending on the [responseMode](#responsemode)) so that the code or tokens are no longer present or visible to the user. For this reason, it is recommended to use a dedicated route or path for the [redirectUri](#configuration-options) so that this URL rewrite does not interfere with other URL parameters which may be used by your application. A complete login flow will usually save the current URL before calling `getWithRedirect` and restore the URL after saving tokens from `parseFromUrl`.
2279
1364
 
2280
1365
  ```javascript
2281
1366
  // On any page while unauthenticated. Begin login flow
@@ -2600,6 +1685,10 @@ authClient.authStateManager.subscribe((authState) => {
2600
1685
 
2601
1686
  Gets latest evaluated `authState` from the `authStateManager`. The `authState` (a unique new object) is re-evaluated when `authStateManager.updateAuthState()` is called. If `updateAuthState` has not been called, or it has not finished calculating an initial state, `getAuthState` will return `null`.
2602
1687
 
1688
+ #### `authStateManager.getPreviousAuthState()`
1689
+
1690
+ Gets the previous evaluated `authState` from the `authStateManager`. This state can be used to tell when the new authState is evaluated. For example, the `authState` is evaluated duing app initialization if the `previousAuthState` is `null`, and the `authState` is evaluated during tokens auto renew process if the `previousAuthState` exists.
1691
+
2603
1692
  #### `authStateManager.updateAuthState()`
2604
1693
 
2605
1694
  Produces a unique `authState` object and emits an `authStateChange` event. The [authState](#authstatemanager) object contains tokens from the `tokenManager` and a calculated `isAuthenticated` value. By default, `authState.isAuthenticated` will be true if both `idToken` and `accessToken` are present. This logic can be customized by defining a custom [transformAuthState](#transformauthstate) function.
@@ -2791,4 +1880,4 @@ const OktaAuth = require('@okta/okta-auth-js').OktaAuth;
2791
1880
 
2792
1881
  ## Contributing
2793
1882
 
2794
- We're happy to accept contributions and PRs! Please see the [contribution guide](contributing.md) to understand how to structure a contribution.
1883
+ We're happy to accept contributions and PRs! Please see the [contribution guide](CONTRIBUTING.md) to understand how to structure a contribution.