API Reference

The WorkOS API enables adding Enterprise Ready features to your application. This REST API provides programmatic access and management of SSO, Magic Link, Directory Sync, and Audit Trail resources.

Sign in to see code examples customized with your API keys and data.

API Base URL

Client Libraries

WorkOS offers native SDKs in several popular programming languages. Choose one language below to see our API Reference in your application’s language.

Don't see an SDK you need? Contact us to request an SDK!

API Keys

WorkOS authenticates your API requests using your account’s API keys. API requests made without authentication or using an incorrect key will return a 401 error. Requests using a valid key but with insufficient permissions will return a 403 error. All API requests must be made over HTTPS. Any requests made over plain HTTP will fail.

Set API Key

You can view and manage your API keys in the WorkOS Dashboard.

Secure your API Keys

API keys can perform any API request to WorkOS. They should be kept secure and private! Be sure to prevent API keys from being made publicly accessible, such as in client-side code, GitHub, unsecured S3 buckets, and so forth. API keys are prefixed with sk_.

In Staging

Your Staging Environment comes with an API key already generated for you. Staging API keys may be viewed as often as they are needed and will appear inline throughout our documentation in code examples if you are logged in to your WorkOS account. API requests will be scoped to the provided key’s Environment.

In Production

Once you unlock Production access you will need to generate an API Key for it. Production API keys may only be viewed once and will need to be saved in a secure location upon creation of them.

Errors

WorkOS uses standard HTTP response codes to indicate the success or failure of your API requests.

  • 2xx – Indicates success.
  • 4xx – Indicates an error, normally due to error caused by incorrect or missing request information (e.g. providing an incorrect API key).
  • 5xx – Indicates a WorkOS server error.

Pagination

Many top-level resources have support for bulk fetches via “list” API methods. For instance, you can list connections, list directory users, and list directory groups. These list API methods share a common structure, taking at least these four parameters: limit, order, after, and before.

WorkOS utilizes pagination via the after and before parameters. Both parameters take an existing object ID value (see below) and return objects in either descending or ascending order by created_at timestamp.

Response with List Metadata
cURL

Webhooks

WorkOS uses webhooks to automatically notify your application any time certain changes are made to your Connections.

A webhook URL is an endpoint hosted by your application that subscribes to notifications from WorkOS. WorkOS sends these notifications as Events which detail changes to users and groups. Each time there is a change, WorkOS makes a request to your application’s webhook URL containing an Event. You’ll receive an Event when new users are created, group properties are updated, or users have been added to a group, just to name a few examples. Each Event contains specific information explaining what happened to trigger the webhook.

Organization

An Organization is a top-level resource in WorkOS. Each Connection, Directory, and Audit Trail Event belongs to an Organization. An Organization will usually represent one of your customers.

Organizations can optionally have Organization Domains which are useful to tag any domains that used across all associated Connections and Directories.

Example Organization

organization

Distinguishes the Organization object.

Unique identifier of the Organization.

A descriptive name for the Organization. This field does not need to be unique.

Whether the Connections within this Organization should allow Profiles that do not have a domain that is present in the set of the Organization’s User Email Domains.

The timestamp when the Organization was last created.

The timestamp when the Organization was last updated.

Get an Organization

Get the details of an existing organization.

Request

GET/organizations/:id

Parameters

Unique identifier of the Organization.

List Organizations

Get a list of all of your existing organizations matching the criteria specified.

Request

GET/organizations

Parameters

The domains of an Organization. Any Organization with a matching domain will be returned.

Upper limit on the number of objects to return, between 1 and 100. The default value is 10.

A cursor to use for pagination. before is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include before=obj_123 to fetch a new batch of objects before obj_123.

A cursor to use for pagination. after is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include after=obj_123 to fetch a new batch of objects after obj_123.

Order the results by the created_at timestamp. Supported values are "asc" and "desc" for ascending and descending order respectively.

Returns

object

Array of Organizations in descending order by created_at timestamp.

A cursor to use for pagination. before is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include before=obj_123 to fetch a new batch of objects before obj_123.

A cursor to use for pagination. after is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include after=obj_123 to fetch a new batch of objects after obj_123.

Create an Organization

Creates a new organization in the current environment.

Request

POST/organizations

Parameters

A descriptive name for the Organization. This field does not need to be unique.

Whether the Connections within this Organization should allow Profiles that do not have a domain that is present in the set of the Organization’s User Email Domains.

The domains of the Organization.

At least one domain is required unless allow_profiles_outside_organization is true.

Update an Organization

Updates an organization in the current environment.

Request

PUT/organizations/:id

Parameters

A descriptive name for the Organization. This field does not need to be unique.

Whether the Connections within this Organization should allow Profiles that do not have a domain that is present in the set of the Organization’s User Email Domains.

The domains of the Organization.

At least one domain is required unless allow_profiles_outside_organization is true.

Delete an Organization

Deletes an organization in the current environment.

Request

DELETE/organizations/:id

Parameters

Unique identifier of the Organization.

Organization Domain

An Organization Domain (also known as a User Email Domain) represents an Organization's domain.

These domains restrict which email addresses are able to sign in through SAML Connections when allow_profiles_outside_organization is false. This is the default behavior for Organizations. See here for more details on this behavior.

Example Organization Domain

organization_domain

Distinguishes the Organization Domain object.

Unique identifier for the Organization Domain.

Domain for the Organization Domain.

Single Sign-On

The Single Sign-On API has been modeled to meet the OAuth 2.0 framework specification. As a result, authentication flows constructed using the Single Sign-On API replicate the OAuth 2.0 protocol flow.

Redirect URI

In the OAuth 2.0 protocol, a redirect URI is the location your user is redirected to once they have successfully authenticated with their Identity Provider.

In Production Environments, the redirect URI to your application must use HTTPS and there should be at least one redirect URI configured and selected as a default for a WorkOS Environment. This can be done from the SSO Configuration page in the WorkOS dashboard. Without a valid redirect URI, users will be unable to sign in.

Redirect URIs that use HTTP and localhost are allowed in Sandbox Environments.

Example Redirect URI

Get Authorization URL

Generate an OAuth 2.0 authorization URL.

WorkOS generates an OAuth 2.0 authorization URL that automatically directs a user to their Identity Provider. Once the user authenticates with their Identity Provider, WorkOS then issues a redirect to your Redirect URI to complete the login flow.

To indicate the connection to use for authentication, use one of the following connection selectors: connection, organization, or provider.

These connection selectors are mutually exclusive, and exactly one must be provided.

Request

GET/sso/authorize

The only valid option for the response type parameter is code.

The code parameter value initiates an Authorization Code Grant Type. This grant type allows a Developer to exchange an authorization code for an access token during the redirect that takes place after a user has authenticated with an Identity Provider.

This value can be obtained from the SSO Configuration page in the WorkOS dashboard.

The connection connection selector is used to initiate SSO for a Connection.

The value of this parameter should be a WorkOS Connection ID.

For example, the Developer can persist the WorkOS Connection ID with application User or Team identifiers. WorkOS will use the Connection indicated by the connection parameter to direct the user to the corresponding IdP for authentication.

The organization connection selector is used to initiate SSO for an Organization.

The value of this parameter should be a WorkOS Organization ID.

For example, the Developer can persist the WorkOS Organization ID with application User or Team identifiers. WorkOS will use the organization connection selector to determine the appropriate Connection and IdP to direct the user to for authentication.

Note that the Organization must only have a single active SSO Connection, otherwise an ambiguous_connection_selector error code will be returned.

The provider connection selector is used to initiate SSO using an OAuth provider.

Currently, the only supported values for provider are GoogleOAuth and MicrosoftOAuth. Provide the provider parameter when authenticating Google OAuth users, because Google OAuth does not take a user’s domain into account when logging in with a “Sign in with Google” button.

Optional parameter that a Developer can choose to include in their authorization URL. If included, then the redirect URI received from WorkOS will contain the exact state that was passed in the authorization URL.

The state parameter can be used to encode arbitrary information to help restore application state between redirects.

Can be used to pre-fill the username/email address field of the IdP sign-in page for the user, if you know their username ahead of time.

Currently, this parameter is only supported for OAuth, and OpenID Connect connection types.

Can be used to pre-fill the domain field when initiating authentication with Microsoft OAuth.

Returns

An OAuth 2.0 authorization URL.

Profile

A Profile is an object that represents an authenticated user. The Profile object contains information relevant to a user in the form of normalized and raw attributes.

After receiving the Profile for an authenticated user, use the Profile object attributes to persist relevant data to your application’s user model for the specific, authenticated user.

No Profile attributes can be returned other than the normalized attributes listed below, and the raw attributes returned by an Identity Provider.

Example Profile

profile

Distinguishes the Profile object.

Unique identifier for the user, assigned by WorkOS.

This value can be persisted to the Developer’s user model and used as a unique key for identifying a specific user.

Unique identifier for the Connection to which the Profile belongs.

The type of SSO Connection used to authenticate the user. Possible values:

  • ADFSSAML
  • Auth0SAML
  • AzureSAML
  • CASSAML
  • CloudflareSAML
  • CyberArkSAML
  • ClassLinkSAML
  • DuoSAML GenericOIDC
  • GenericSAML GoogleOAuth
  • GoogleSAML
  • JumpCloudSAML
  • KeycloakSAML
  • LastPassSAML
  • MicrosoftOAuth
  • MiniOrangeSAML
  • NetIqSAML
  • OktaSAML
  • OneLoginSAML
  • OracleSAML
  • PingFederateSAML
  • PingOneSAML
  • SalesforceSAML
  • SimpleSamlPhpSAML
  • VMwareSAML

Unique identifier for the Organization in which the Connection resides.

The user’s email address.

The user’s first name.

The user’s last name.

Unique identifier for the user, assigned by the Identity Provider. Different Identity Providers use different ID formats.

One possible use case for idp_id is associating a user’s SSO Profile with any relevant Directory Sync actions related to that user.

Object of key-value pairs containing relevant user data from the Identity Provider.

Raw attributes are an extended set of information one can expect for each user Profile. These raw attributes will vary by Identity Provider and Identity Provider configuration.

Get a Profile and Token

Get an access_token along with the user’s Profile using the code we passed to your Redirect URI.

Request

POST/sso/token

Parameters

This value can be obtained from the SSO Configuration page in the WorkOS dashboard.

This is the same value as the WorkOS Environment’s secret API key.

This value can be obtained from the API Keys page in the WorkOS dashboard.

The method by which your application will receive an access token. This value should be authorization_code.

The authorization value which was passed back as a query parameter in the callback to the Redirect URI.

Returns

object

An access token that can be exchanged for a user profile. Access tokens are one-time use and expire 10 minutes after they’re created.

The user Profile object.

Get a User Profile

Exchange an access_token for a user’s Profile. Because this profile is returned in the Get a Profile and Token endpoint your application usually does not need to call this endpoint. It is available for any authentication flows that require an additional endpoint to retrieve a user’s profile.

Request

GET/sso/profile

Parameters

The authorization value which was returned along with the profile when calling the Get a Profile and Token endpoint.

Returns

profile

Connection

A Connection represents the relationship between WorkOS and any collection of application users. This collection of application users may include personal or enterprise Identity Providers, or passwordless authentication methods like Magic Link. As a layer of abstraction, a WorkOS Connection rests between an application and its users, separating an application from the implementation details required by specific standards like OAuth 2.0 and SAML.

Example Connection

connection

Distinguishes the Connection object.

Unique identifier for the Connection.

Unique identifier for the Organization in which the Connection resides.

The type of SSO Connection used to authenticate a user.

One possible use case for connection_type is dynamically generating authorization URLs. Possible values:

  • ADFSSAML
  • ADPOIDC
  • Auth0SAML
  • AzureSAML
  • CASSAML
  • ClassLinkSAML
  • CloudflareSAML
  • CyberArkSAML
  • DuoSAML
  • GenericOIDC
  • DuoSAML
  • GenericSAML
  • GoogleOAuth
  • GoogleSAML
  • JumpCloudSAML
  • KeycloakSAML
  • LastPassSAML
  • MicrosoftOAuth
  • MiniOrangeSAML
  • NetIqSAML
  • OktaSAML
  • OneLoginSAML
  • OracleSAML
  • PingFederateSAML
  • PingOneSAML
  • SalesforceSAML
  • SimpleSamlPhpSAML
  • ShibbolethSAML
  • ShibbolethGenericSAML
  • VMwareSAML

A human-readable name for the Connection. This will most commonly be the Enterprise Client’s name.

Indicates whether a Connection is able to authenticate users. Possible values:

  • draft
  • active
  • inactive

The timestamp when the Connection was created.

The timestamp when the Connection was last updated.

Get a Connection

Get the details of an existing connection.

Request

GET/connections/:id

Parameters

Unique identifier for the Connection.

Returns

connection

List Connections

Get a list of all of your existing connections matching the criteria specified.

Request

GET/connections

Parameters

Filter Connections by their type.

Filter Connections by their associated domain.

Filter Connections by their associated organization.

A cursor to use for pagination. after is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include after=obj_123 to fetch a new batch of objects after obj_123.

A cursor to use for pagination. before is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include before=obj_123 to fetch a new batch of objects before obj_123.

Upper limit on the number of objects to return, between 1 and 100. The default value is 10.

Order the results by the created_at timestamp. Supported values are "asc" and "desc" for ascending and descending order respectively.

Returns

object

An array of Connections in descending order by created_at timestamp.

A cursor to use for pagination. before is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include before=obj_123 to fetch a new batch of objects before obj_123.

A cursor to use for pagination. after is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include after=obj_123 to fetch a new batch of objects after obj_123.

Delete a Connection

Delete an existing connection.

Request

DELETE/connections/:id

Parameters

Unique identifier for the Connection.

Connection Webhooks

Triggers when a connection has been activated, deactivated, or deleted.

Activated

connection.activated connection.deactivated connection.deleted

The type of webhook event.

Unique identifier for the webhook.

The updated Connection.

When receiving a connection.deleted event you can ignore the connection’s state attribute, since it indicates the state before the deletion occurs.

Directory Sync

Directory Sync allows you to connect with Directory Providers to inform your application of any changes in their users, groups, or access rules.

Using Directory Sync, one integration grants your application the ability to support multiple Directory Providers. Get real-time updates of any changes to your Enterprise Client’s access rules, groups, and users by integrating webhooks into your application.

Directory

A Directory stores information about an Enterprise Client’s employee management system.

Synchronizing with a Directory enables Developers to receive changes to an Enterprise Client’s User and Group structure.

Directory Providers vary in implementation details and may require different sets of fields for integration, such as API keys, subdomains, endpoints, usernames, etc. Where available, the WorkOS API will provide these fields when fetching Directory records.

Example Directory

directory

Unique identifier for the Directory.

The URL associated with an Enterprise Client.

The name of the directory.

The unique identifier for the Organization in which the directory resides.

Describes whether the Directory has been successfully connected to an external provider.

  • linked
  • unlinked
  • validating
  • deleting
  • invalid_credentials

The type of external Directory Provider integrated with.

  • azure scim v2.0
  • bamboohr
  • breathe hr
  • generic scim v1.1
  • generic scim v2.0
  • gsuite directory
  • jump cloud scim v2.0
  • okta scim v1.1
  • okta scim v2.0
  • onelogin scim v2.0
  • people hr
  • pingfederate scim v2.0
  • workday

The timestamp when the Directory was created.

The timestamp when the Directory was last updated.

Get a Directory

Get the details of an existing directory.

Request

GET/directory/:id

Parameters

Unique identifier for the Directory.

Returns

directory

List Directories

Get a list of all of your existing directories matching the criteria specified.

Request

GET/directories

Parameters

The domain of a Directory.

Searchable text to match against Directory names.

Filter Directories by their associated organization.

Upper limit on the number of objects to return, between 1 and 100. The default value is 10.

A cursor to use for pagination. before is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include before=obj_123 to fetch a new batch of objects before obj_123.

A cursor to use for pagination. after is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include after=obj_123 to fetch a new batch of objects after obj_123.

Order the results by the created_at timestamp. Supported values are "asc" and "desc" for ascending and descending order respectively.

Returns

object

Array of Directories in descending order by created_at timestamp.

A cursor to use for pagination. after is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include after=obj_123 to fetch a new batch of objects after obj_123.

A cursor to use for pagination. before is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include before=obj_123 to fetch a new batch of objects before obj_123.

Delete a Directory

Delete an existing directory.

Request

DELETE/directories/:id

Parameters

Unique identifier for the Directory.

Directory Webhooks

Triggers when a directory has been activated, deactivated, or deleted.

Activated

dsync.activated dsync.deactivated dsync.deleted

The type of webhook event.

Unique identifier for the webhook.

The updated Directory.

When receiving a dsync.deleted event you can ignore the connection’s state attribute, since it indicates the state before the deletion occurs.

Directory User

A Directory User represents an active Enterprise user.

Developers can receive Webhooks as employees are added, updated or removed, allowing for provisioning and de-provisioning Users within an application.

The data stored for employees vary per Directory provider and may include attributes such as photo URLs, pay groups, supervisors, etc. Where available, the WorkOS API will provide the additional data in the raw_attributes field when fetching Directory User records.

Example Directory User

directory_user

Unique identifier for the Directory User.

Unique identifier for the user, assigned by the Directory Provider. Different Directory Providers use different ID formats.

One possible use case for idp_id is associating the Directory User with their SSO Profile.

The identifier of the Directory the Directory User belongs to.

The identifier for the Organization in which the Directory resides.

The first name of the user.

The last name of the user.

The emails of the user.

The username of the user.

The groups that the user is a member of.

The state of the user.

  • active
  • suspended
  • inactive

An object containing the custom attribute mapping for the Directory Provider.

An object containing the data returned from the Directory Provider.

The timestamp when the Directory User was created.

The timestamp when the Directory User was last updated.

Get a Directory User

Get the details of an existing Directory User.

Request

GET/directory_users/:id

Parameters

Unique identifier for the Directory User.

List Directory Users

Get a list of all of existing Directory Users matching the criteria specified.

Request

GET/directory_user

Parameters

Unique identifier of the WorkOS Directory.

This value can be obtained from the WorkOS dashboard or from the WorkOS API.

Unique identifier of the WorkOS Directory Group.

This value can be obtained from the WorkOS API.

Upper limit on the number of objects to return, between 1 and 100. The default value is 10.

A cursor to use for pagination. before is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include before=obj_123 to fetch a new batch of objects before obj_123.

A cursor to use for pagination. after is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include after=obj_123 to fetch a new batch of objects after obj_123.

Order the results by the created_at timestamp. Supported values are "asc" and "desc" for ascending and descending order respectively.

Returns

object

Array of Directory Users in descending order by created_at timestamp.

Since these can be bulk processed (ex. 10 updates were batched process), there is a secondary sort on the identifier, i.e. id.

A cursor to use for pagination. after is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include after=obj_123 to fetch a new batch of objects after obj_123.

A cursor to use for pagination. before is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include before=obj_123 to fetch a new batch of objects before obj_123.

Directory User Webhooks

Triggers when a user has been created, updated, or deleted.

Created

dsync.user.created dsync.user.updated dsync.user.deleted

The type of webhook event.

Unique identifier for the webhook.

The updated Directory User.

Previous Attributes

The payload for dsync.user.updated webhooks shows changes between Directory Group snapshots in a previous_attributes property.

The changes in the object are shallow differences for root properties, raw_attributes, and custom_attributes. If the current snapshot has a new attribute that did not exist previously, then the value for the attribute will be indicated as null.

Directory Group

A Directory Group represents an Enterprise organizational unit of users.

Developers can receive Webhooks as groups are added, updated, or removed, allowing for group-based resource access.

At this time, only the Group identifier and name attributes are returned.

Example Directory Group

directory_group

Unique identifier for the Directory Group.

Unique identifier for the group, assigned by the Directory Provider. Different Directory Providers use different ID formats.

The identifier of the Directory the Directory Group belongs to.

The identifier for the Organization in which the Directory resides.

The name of the Directory Group.

The timestamp when the Directory Group was created.

The timestamp when the Directory Group was last updated.

An object containing the data returned from the Directory Provider.

Get a Directory Group

Get the details of an existing Directory Group.

Request

GET/directory_groups/:id

Parameters

Unique identifier for the Directory Group.

List Directory Groups

Get a list of all of existing directory groups matching the criteria specified.

Request

GET/directory_groups

Parameters

Unique identifier of the WorkOS Directory.

This value can be obtained from the WorkOS dashboard or from the WorkOS API.

Unique identifier of the WorkOS Directory User.

This value can be obtained from the WorkOS API.

Upper limit on the number of objects to return, between 1 and 100. The default value is 10.

A cursor to use for pagination. before is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include before=obj_123 to fetch a new batch of objects before obj_123.

A cursor to use for pagination. after is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include after=obj_123 to fetch a new batch of objects after obj_123.

Order the results by the created_at timestamp. Supported values are "asc" and "desc" for ascending and descending order respectively.

Returns

object

Array of Directory Groups in descending order by created_at timestamp.

A cursor to use for pagination. after is an object ID that defines your place in the list. For example, if you make a list request and receive 100 objects, ending with obj_123, your subsequent call can include after=obj_123 to fetch a new batch of objects after obj_123.

Directory Group Webhooks

Triggers when a group has been created, updated, or deleted. It also triggers when a user is added or removed from a group.

Created

dsync.group.created dsync.group.updated dsync.group.deleted dsync.group.user_added dsync.group.user_removed

The type of webhook event.

Unique identifier for the webhook.

Previous Attributes

The payload for dsync.group.updated webhooks shows changes between Directory Group snapshots in a previous_attributes property.

The changes in the object are shallow differences for root properties, raw_attributes, and custom_attributes. If the current snapshot has a new attribute that did not exist previously, then the value for the attribute will be indicated as null.

Admin Portal

The Admin Portal is a standalone application where your users can configure and manage WorkOS resources such as Connections and Directories that are scoped to their Organization.

Portal Link

A Portal Link is a temporary endpoint to initiate an Admin Portal session. It expires five minutes after issuance.

Example Portal Link URL

Generate a Portal Link

Generate a Portal Link scoped to an Organization.

Request

POST/portal/generate_link

Parameters

An Organization identifier.

The intent of the Admin Portal.

  • sso - Launch Admin Portal for creating SSO connections
  • dsync - Launch Admin Portal for creating directory sync connections

The URL to which WorkOS should send users when they click on the link to return to your website.

Returns

object

An ephemeral link to initiate the Admin Portal.

Magic Link

The Magic Link API can be used to add Passwordless Authentication to your app.

Passwordless Session

An object representing a passwordless authentication session.

Example Passwordless Session

passwordless_session

Distinguishes the Paswordless Session object.

The unique ID of the session.

The email address of the user for the session.

The ISO-8601 datetime at which the session expires.

The link for the user to authenticate with. You can use this link to send a custom email to the user, or send an email using Email a Magic Link to the user.

Once a user has authenticated with the link, WorkOS issues a redirect to the Environment’s default redirect URI, with a code parameter and, if provided during session creation, a state parameter.

Code can then be exchanged for an access token and user Profile. To perform this exchange, the Developer should make aPOST request to the /sso/token endpoint.

If the link has expired, WorkOS will issue a redirect with an error query parameter and value of access_denied.

Create Passwordless Session

Create a Passwordless Session for a Magic Link Connection.

Request

POST/passwordless/sessions

Parameters

The email of the user to authenticate.

The type of Passwordless Session to create. Currently, the only supported value is MagicLink.

Value containing the ID of a specific Connection.

This can be used to create a Passwordless Session for a specific Connection rather than relying on the domain from the email to determine the Organization and Connection.

Optional parameter that a developer can choose to include in their authorization URL. If included, it will override the default Redirect URI set in the dashboard. This is the location your user will be redirected to once the session has been completed successfully.

The number of seconds the Passwordless Session should live before expiring.

This value must be between 300 (5 minutes) and 86400 (24 hours), inclusive.

Optional parameter that a developer can choose to include in their authorization URL. If included, then the redirect URI received from WorkOS will contain the exact state that was passed in the authorization URL.

The state parameter can be used to encode arbitrary information to help restore application state between redirects.

Email a Magic Link

Email a user the Magic Link confirmation URL.

Request

POST/passwordless/sessions/:id/send

Parameters

The unique identifier of the Passwordless Session to send an email for.

Returns

object

A confirmation that the Magic Link was sent.

Multi-Factor Authentication

The multi-factor authentication (MFA) API can be used to add additional factors of authentication to existing authentication strategies.

The API currently supports both time-based one-time passwords (TOTP) and SMS factors.

Authentication Factor

An object representing an Authentication Factor.

Example Authentication Factor

authentication_factor

Distinguishes the Authentication Factor object.

The unique ID of the Factor.

The timestamp when the Factor was created.

The timestamp when the Factor was last updated.

The type the Factor. Can be either totp or sms.

Base64 encoded image containing scannable QR code.

TOTP secret that can be manually entered into some authenticator apps in place of scanning QR code.

The otpauth URI that is encoded the provided qr_code.

Phone number that the Factor was enrolled with.

Authentication Challenge

An object representing a Challenge of an Authentication Factor.

Example Authentication Challenge

authentication_challenge

Distinguishes the Authentication Challenge object.

The unique ID of the Authentication Challenge.

The timestamp when the Challenge was created.

The timestamp when the Challenge was last updated.

The timestamp when the Challenge will expire. Does not apply to totp factors.

The unique ID of the Authentication Factor the Challenge belongs to.

Enroll Factor

Enrolls an Authentication Factor to be used as an additional factor of authentication. The returned ID should can later be used to create an authentication Challenge.

Request

POST/auth/factors/enroll

Parameters

The type of factor you wish to enroll.

  • totp
  • sms

An identifier for the organization issuing the challenge. Should be the name of your application or company. Required when type is totp.

An identifier for the user. Used by authenticator apps to label connections. Required when type is totp.

A valid phone number for an SMS enabled device. Required when type is sms.

Challenge Factor

Creates a Challenge for an Authentication Factor.

Request

POST/auth/factors/:id/challenge

Parameters

The unique ID of the Authentication Factor to be challenged.

Optional template for SMS messages. Only applicable for sms Factors. Use the {{code}} token to inject the one-time code into the message. E.g., Your Foo Corp one-time code is {{code}}.

Verify Challenge

Verify Authentication Challenge.

Request

POST/auth/challenges/:id/verify

Parameters

The unique ID of the authentication Challenge.

The 6 digit code to be verified.

Returns

object

Indicates whether the code was correct.