# Single Sign-On

The Single Sign-On API has been modeled to meet the [OAuth 2.0](/glossary/oauth-2-0) framework specification. As a result, authentication flows constructed using the Single Sign-On API replicate the OAuth 2.0 protocol flow.

To automatically respond to changes in your SSO connections, use the [Connection events](/events/connection).

### profile

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

To surface additional attributes on the Profile, refer to the [SSO custom attributes](/sso/attributes/custom-attributes) guide.

### get-user-profile

## Get a User Profile

Exchange an access token for a user’s [Profile](/reference/sso/profile). Because this profile is returned in the [Get a Profile and Token endpoint](/reference/sso/profile/get-profile-and-token) 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.

### get-profile-and-token

## Get a Profile and Token

Get an access token along with the user [Profile](/reference/sso/profile) using the code passed to your [Redirect URI](/reference/sso/get-authorization-url/redirect-uri).

### redirect

## Logout Redirect

Logout allows to sign out a user from your application by triggering the identity provider sign out flow.
This `GET` endpoint should be a redirection, since the identity provider user will be identified in the browser session.

Before redirecting to this endpoint, you need to generate a short-lived logout token using the
[Logout Authorize](/reference/sso/logout/authorize) endpoint.

### logout

## Logout

The Logout endpoints enable the RP-initiated logout functionality for users in your application.
Refer to [Single Logout](/sso/single-logout/idp-initiated-logout) section for more details on how to handle
RP-initiated or IdP-initiated logout.

> Please note that the Logout feature is only available for Custom Open ID connections that provide
> specific logout features. These features include the presence of the `revocation_endpoint` and `end_session_endpoint`
> in the discovery document.

### authorize

## Logout Authorize

You should call this endpoint from your server to generate a logout token which is required for
the [Logout Redirect](/reference/sso/logout) endpoint.

### redirect-uri

### Redirect URI

In the [OAuth 2.0](/glossary/oauth-2-0) protocol, a redirect URI is the location that the user is redirected to once they have successfully authenticated with their identity provider.

When redirecting the user, WorkOS will generate an authorization code and pass it to your redirect URI as a `code` query parameter, your app will use this code to [get the user’s profile](/reference/sso/profile/get-profile-and-token). Additionally, WorkOS can pass a `state` parameter back to your application that you may use to encode arbitrary information to restore your application state between the redirects.

```url title="Redirect URI with query parameters"
https://your-app.com/callback?code=01E2RJ4C05B52KKZ8FSRDAP23J&state=dj1kUXc0dzlXZ1hjUQ==
```

You’ll need to configure the allowed redirect URIs for your application via the [Redirects](https://dashboard.workos.com/redirects) page in the dashboard. Without a valid redirect URI, your users will be unable to sign in. Make sure that the redirect URI you use as a parameter to get the authorization URL matches one of the redirect URIs you have configured in the dashboard.

Redirect URIs follow stricter requirements in production environments:

- `HTTPS` protocol is required in production environments
- `HTTP` and `localhost` are allowed in staging environments
- Wildcard characters are not allowed in production environments

#### Wildcards

WorkOS supports using wildcard characters in Redirect URIs. The `*` symbol can be used as a wildcard for subdomains; however, it must be used in accordance with the following rules in order to properly function.

- The wildcard **must** be located in a subdomain within the hostname component. For example, `http://*.com` will not work.
- The wildcard **must** be located in the subdomain which is furthest from the root domain. For example, `https://sub.*.example.com` will not work.
- The URL **must not** contain more than one wildcard. For example, `https://*.*.example.com` will not work.
- A wildcard character **may** be prefixed and/or suffixed with additional valid hostname characters. For example, `https://prefix-*-suffix.example.com` will work.
- A URL with a valid wildcard **will not** match a URL more than one subdomain level in place of the wildcard. For example, `https://*.example.com` will not work with `https://sub1.sub2.example.com`.
- In production environments, wildcards cannot be used with [public suffix domains](https://publicsuffix.org). For example, `https://*.ngrok-free.app` will not work.
- The wildcard will match a sequence of letters (`A` through `Z`, and `a` through `z` ); digits (`0` through `9`), hyphens (`-`), and underscores (`_`). For example, `https://user:secret@foo.example.com` will not work with `https://*.example.com`.
- A URL with a wildcard cannot be set as the default redirect URI.

### get-authorization-url

## Get an authorization URL

Generates an OAuth 2.0 authorization URL to authenticate a user with SSO.



You’ll have to specify the user’s connection, organization, or OAuth provider as a parameter. These connection selectors are mutually exclusive, and exactly one must be provided. The generated URL automatically directs the 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 sign-in flow.

### error-codes

### Error codes

If there is an issue generating an authorization URL, the API will return the original redirect URI with `error` and `error_description` query parameters. If provided, the `state` value will also be included.

```url title="Redirect URI with an error code"
https://your-app.com/callback?error=organization_invalid&error_description=No%20connection%20associated%20with%20organization&state=123456789
```

Possible error codes and the corresponding descriptions are listed below.

| Error code                                 | Description                                                                                                                                                                                                                                                                                                                        |
| ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `access_denied`                            | The identity provider denied the user's access to the client application, or the user declined the OAuth authorization request at the identity provider.                                                                                                                                                                           |
| `ambiguous_connection_selector`            | A connection could not be uniquely identified using the provided connection selector (e.g., organization). This can occur when there are multiple SSO connections under the same organization. If you need multiple SSO connections for an organization, use the connection parameter to identify which connection to use for SSO. |
| `connection_domain_invalid`                | There is no connection for the provided domain.                                                                                                                                                                                                                                                                                    |
| `connection_invalid`                       | There is no connection for the provided ID.                                                                                                                                                                                                                                                                                        |
| `connection_strategy_invalid`              | The provider has multiple strategies associated per environment.                                                                                                                                                                                                                                                                   |
| `connection_unlinked`                      | The connection associated with the request is unlinked.                                                                                                                                                                                                                                                                            |
| `domain_connection_selector_not_allowed`   | This is a legacy error code that only applies if using the deprecated “domain” query parameter which is no longer valid for this endpoint. Use the “organization” or “connection” query parameters to target a connection instead.                                                                                                 |
| `idp_initiated_sso_disabled`               | IdP-initiated SSO is disabled for the connection (see [Disable IdP-initiated SSO](/sso/login-flows/idp-initiated-sso/disable-idp-initiated-sso-beta)).                                                                                                                                                                             |
| `invalid_connection_selector`              | A valid connection selector query parameter must be provided in order to correctly determine the proper connection to return an authorization URL for. Valid connection selectors are either `connection`, `organization`, or `provider`.                                                                                          |
| `organization_invalid`                     | There is no organization matching the provided ID.                                                                                                                                                                                                                                                                                 |
| `oauth_failed`                             | An OAuth authorization request failed for a user.                                                                                                                                                                                                                                                                                  |
| `profile_not_allowed_outside_organization` | A profile was received that has an `email` that is outside the [organization’s domain](/reference/organization-domain) and the organization does not allow this. To resolve this, add the missing domain to the organization's Domains. You can read about other options in the [SSO Domains guide](/sso/domains).                 |
| `server_error`                             | The SSO authentication failed for the user. More detailed errors and steps to resolve are available in the Sessions tab on the connection page in the WorkOS Dashboard.                                                                                                                                                            |
| `signin_consent_denied`                    | The user rejected the sign-in consent screen. This screen prompts the user to verify the email provided by the identity provider to confirm the legitimacy of the sign-in attempt.                                                                                                                                                 |

### list

## List Connections

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

### connection

## 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. 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](/glossary/oauth-2-0) and [SAML](/glossary/saml).

See the [events reference](/events/connection) documentation for the connection events.

### get

## Get a Connection

Get the details of an existing connection.

### delete

## Delete a Connection

Permanently deletes an existing connection. It cannot be undone.

### list-for-organization

## List roles for an organization

Get a list of all roles for the provided organization in priority order. Includes all environment and organization roles.

### Roles