❕ The use of this module requires usage of the Okta Identity Engine. This functionality is in general availability but is being gradually rolled out to customers. If you want to request to gain access to the Okta Identity Engine, please reach out to your account manager. If you do not have an account manager, please reach out to [email protected] for more information.
This module is built to communicate with Okta as an OAuth 2.0 + OpenID Connect provider. It works with Okta's Identity Engine to authenticate and register users.
To see this library working in a sample, check out our Embedded auth with SDKs sample.
See detail in Using the npm module.
This module provides convenience methods to support popular scenarios to communicate with Okta's Identity Engine.
You can work with these methods with Up-Front
and On-Demand
approaches, normally a mix of both approaches will be needed when user inputs are required in the middle of the flow (e.g. multiple factors auth). Below are the general explaination of these two approaches, more code examples will be provided with the specific methods.
You can provide parameters based on your app's policy configuration and user inputs to drive the methods to communicate with Okta's Identity Engine.
You can provide minimum or even no parameters to call the methods, and the methods can provide direction for the flow by indicating the nextStep
and required inputs
.
Most methods in this module resolve IdxTransaction as the response. With Okta's Identity Engine's dynamic nature, it's very important to understand how to follow the response to proceed to the next step.
This field indicates the status of the current flow.
IdxStatus.SUCCESS
: This status indicates the flow has ended successfully with tokens.IdxStatus.PENDING
: This status indicates the flow is still in progress, checknextStep
andmessages
(intermediate form errors) fields in the response to proceed.IdxStatus.FAILURE
: This status indicates error has happened in SDK level, checkerror
field in the response for error handling.IdxStatus.TERMINAL
: This status indicates the flow has run into aterminal
state, checkmessages
field to handle it.IdxStatus.CANCELED
: This status indicates the flow has been canceled. It's normally the response status ofidx.cancel
.
This field contains information to proceed with the next step. It's avaiable when in IdxStatus.PENDING
status.
-
name
: The identifier of the next step. -
type?
: The type of the authenticator that the step belongs to. -
canSkip?
: This field indicates if the step is skippable or not. -
inputs?
: parameters for the next step.// get "inputs" from the response // inputs: [{ name: 'username', label: 'Username' }] const { nextStep: { inputs } } = await authClient.idx.authenticate(); // gather user inputs (this call should happen in a separated request) const transaction = await authClient.idx.authenticate({ username: 'from user input' });
-
options?
: This field is available in response when the input is a selection. It can also provide information for how to build UI for the next step.
It's available with IdxStatus.SUCCESS
status. Provides tokens set based on scopes configuration.
It passes back messages from Okta's Identity Engine. Form message
and Terminal message
both come to this field.
It's avaialbe with IdxStatus.FAILURE
status when the SDK run into unhandlable state.
It provides transaction meta (pkce meta, interactionHandle, etc.).
It indicates what features are available based on the app / org policy configuration.
It provides information for avaiable next steps.
The convenience method for authentication
flow.
Example (Two factors auth with email authenticator):
Up-Front:
const {
status, // IdxStatus.PENDING
nextStep: {
inputs // [{ name: 'verificationCode', ... }]
}
} = await authClient.idx.authenticate({
username: 'xxx',
password: 'xxx',
authenticators: ['email']
});
// gather verification code from email (this call should happen in a separated request)
const {
status, // IdxStatus.SUCCESS
tokens
} = await authClient.idx.authenticate({ verificationCode: 'xxx' });
On-Demand:
// start the flow with no param
const {
status, // IdxStatus.PENDING
nextStep: {
inputs // [{ name: 'username', ... }, { name: 'password', ... }]
}
} = await authClient.idx.authenticate();
// gather user inputs (this call should happen in a separated request)
const {
status, // IdxStatus.PENDING
nextStep: {
inputs, // [{ name: 'authenticator', ... }]
options // [{ name: 'email', ... }, ...]
}
} = await authClient.idx.authenticate({ username: 'xxx', password: 'xxx' });
// select authenticator (this call should happen in a separated request)
const {
status, // IdxStatus.PENDING
nextStep: {
inputs // [{ name: 'verificationCode', ... }]
}
} = await authClient.idx.authenticate({ authenticator: 'email' });
// gather verification code from email (this call should happen in a separated request)
const {
status, // IdxStatus.SUCCESS
tokens
} = await authClient.idx.authenticate({ verificationCode: 'xxx' });
The convenience method for self service registration
flow.
Example (Registration with password authenticator enrollment)
Up-Front:
const {
status, // IdxStatus.PENDING
nextStep: {
inputs // [{ name: 'password', ... }]
}
} = await authClient.idx.register({
firstName: 'xxx',
lastName: 'xxx',
email: 'xxx',
authenticators: ['password']
});
// gather password from user input (this call should happen in a separated request)
const {
status, // IdxStatus.SUCCESS
tokens
} = await authClient.idx.register({ password: 'xxx' });
On-Demand:
const {
status, // IdxStatus.PENDING
nextStep: {
inputs // [{ name: 'firstName', ... }, { name: 'lastName', ... }, { name: 'email', ... }]
}
} = await authClient.idx.register();
// gather user inputs (this call should happen in a separated request)
const {
status, // IdxStatus.PENDING
nextStep: {
inputs, // [{ name: 'authenticator', ... }]
options // [{ name: 'password', ... }, ...]
}
} = await authClient.idx.register({
firstName: 'xxx',
lastName: 'xxx',
email: 'xxx'
});
// select authenticator (this call should happen in a separated request)
const {
status, // IdxStatus.PENDING
nextStep: {
inputs // [{ name: 'password', ... }]
}
} = await authClient.idx.register({ authenticator: 'password' });
// gather password from user input (this call should happen in a separated request)
const {
status, // IdxStatus.SUCCESS
tokens
} = await authClient.idx.register({ password: 'xxx' });
The convenience method for self service password recovery
flow.
Example (Password recovery with email authenticator verification)
Up-Front:
const {
status, // IdxStatus.PENDING
nextStep: {
inputs // [{ name: 'verificationCode', ... }]
}
} = await authClient.idx.recoverPassword({
username: 'xxx',
authenticators: ['email']
});
// gather password from user input (this call should happen in a separated request)
const {
status, // IdxStatus.PENDING
nextStep: {
inputs // [{ name: 'password', ... }]
}
} = await authClient.idx.recoverPassword({ verificationCode: 'xxx' });
// gather verification code from email (this call should happen in a separated request)
const {
status, // IdxStatus.SUCCESS
tokens
} = await authClient.idx.recoverPassword({ password: 'xxx' });
On-Demand:
const {
status, // IdxStatus.PENDING
nextStep: {
inputs // [{ name: 'username', ... }]
}
} = await authClient.idx.register();
// gather username from user input (this call should happen in a separated request)
const {
status, // IdxStatus.PENDING
nextStep: {
inputs, // [{ name: 'authenticator', ... }]
options // [{ name: 'email', ... }, ...]
}
} = await authClient.idx.register({ username });
// select authenticator (this call should happen in a separated request)
const {
status, // IdxStatus.PENDING
nextStep: {
inputs // [{ name: 'verificationCode', ... }]
}
} = await authClient.idx.register({ authenticator: 'email' });
// gather verification code from email (this call should happen in a separated request)
const {
status,
nextStep: {
inputs // [{ name: 'password', ...}]
}
} = await authClient.idx.register({ verificationCode: 'xxx' });
// gather new password from user input (this call should happen in a separated request)
const {
status, // IdxStatus.SUCCESS
tokens
} = await authClient.idx.register({ password: 'xxx' });
Resolves Start Transaction related fields.
Popular use cases:
- Provides
meta
for Okta Sign-In Widget integration. - Provides
enabledFeatures
andavailableSteps
for dynamic UI rendering.
Cancels the in progress idx interaction transaction.
await authClient.idx.cancel();
Handles interaction_code
from Okta's Identity Engine's callback url. It exchanges the code for tokens and saves them in storage.
try {
// handle interactionCode and save tokens
await authClient.idx.handleInteractionCodeRedirect(callbackUrl);
} catch (err) {
if (authClient.isInteractionRequiredError(err)) {
// need to proceed with required authenticator/s
}
throw err;
}