New Ory Agent Security is now live! Claim your complimentary test drive. Get Started!

Skip to main content

Single Sign-On

Ory Polis takes a multi-tenanted approach to implementing SSO, abstracting away all the complexities of the underlying SAML/OIDC protocol. What this means is you can enable SSO for all your customers across products from a single instance of Ory Polis, and works with both SAML and OIDC Identity Providers (IdPs).

Note: All the APIs below support both application/x-www-form-urlencoded and application/json content types. Examples below use application/x-www-form-urlencoded.

Note: OAuth 2.0 protocol uses underscore casing for the parameters, we use camel casing for all Ory Polis APIs. For example it's client_id in the OAuth 2.0 flow and clientID in Ory Polis APIs.

Set up SSO provider​

Please follow the instructions here to guide your customers in setting up SAML/OIDC correctly for your product(s). You should create a copy of the doc and modify it with your custom settings, we have used the values that work for Ory Polis demo apps.

SSO Connection API​

You will need to provide a place in the UI for your customers (The account settings page is usually a good place for this) to configure this and then call the APIs below.

Add connection​

Once your customer has set up the SAML app on their Identity Provider, the Identity Provider will generate an IdP or SP metadata file. Some Identity Providers only generate an IdP metadata file but it usually works for the SP login flow as well. It is an XML file that contains various attributes Ory Polis needs to validate incoming SAML login requests. This step is the equivalent of setting an OAuth 2.0 app and generating a client ID and client secret that will be used in the login flow.

The following API call sets up the connection in Ory Polis:

curl --location --request POST 'http://localhost:5225/api/v1/sso' \
--header 'Authorization: Api-Key <Ory Polis API Key>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'encodedRawMetadata=Base64(<IdP/SP metadata XML>)' \
--data-urlencode 'defaultRedirectUrl=http://localhost:3366/login/saml' \
--data-urlencode 'redirectUrl=http://localhost:3366/*' \
--data-urlencode 'redirectUrl=http://localhost:3000/*' \
--data-urlencode 'tenant=ory.com' \
--data-urlencode 'product=demo' \
--data-urlencode 'name=demo-connection' \
--data-urlencode 'description=Demo SAML connection'
  • metadataUrl: URL containing the SAML metadata contents. Either this or encodedRawMetadata needs to be specified

  • encodedRawMetadata: Base64 encoding of the XML metadata your customer gets from their Identity Provider. Either this or metadataUrl needs to be specified

  • defaultRedirectUrl: The redirect URL to use in the IdP login flow. Ory Polis will call this URL after completing an IdP login flow.

  • redirectUrl: Allowed redirect URL. Repeat this field multiple times to allow multiple redirect URLs. Ory Polis will disallow any redirects not on this list (or not the default URL above).

    Both fields accept the private-use schemes native apps register, such as com.example.app:/oauth2redirect or myapp://callback. Ory Polis rejects the schemes a browser executes as script (javascript:, data:, vbscript:) and URLs that embed credentials in the authority.

    An entry is matched on scheme, host and port, so it allows any path under the same origin — and a private-use scheme with no host, such as com.example.app:, allows any URL using that scheme. Set OPENID_REDIRECT_EXACT_MATCH to compare the full URL instead.

  • tenant: Ory Polis supports a multi-tenant architecture, this is a unique identifier you set from your side that relates back to your customer's tenant. This is normally an email, domain, an account id, or user-id. Should not contain the : character since we use it as a delimiter internally

  • product: Ory Polis support multiple products, this is a unique identifier you set from your side that relates back to the product your customer is using. Should not contain the : character since we use it as a delimiter internally

  • name: A friendly name to identify the SAML connection

  • description: A short description with some information of the connection

  • acsUrlId: Optional, an Enterprise feature. A unique identifier (4-64 URL-safe characters) that gives the connection its own ACS endpoint at /api/oauth/saml/<acsUrlId>. See Per-connection ACS URLs.

  • acsUrlHost: Optional, an Enterprise feature. The hostname to associate with this connection's ACS URL. When omitted, Ory Polis uses the ACS_URL_HOST config value.

  • additionalAcsUrls: Optional, an Enterprise feature. Up to 10 further http(s) URLs that the IdP may address SAML responses to, besides the connection's own ACS URL. Repeat this field for each URL. Requires acsUrlId, because Ory Polis checks them only on the connection's own ACS route. See Additional ACS URLs.

  • idpInitiatedLoginEnabled (for SAML SSO Connections): Controls IdP-initiated login for this connection. Set to true to always allow it, or false to always block it. When you leave it unset, the connection follows the deployment-wide IDP_ENABLED switch. Enable IdP-initiated login only where you need it, and review the security considerations first.

  • identifierFormat (for SAML SSO Connections): The NameID format Ory Polis requests from the IdP in the NameIDPolicy of the SAML request. Defaults to urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress.

The response returns a JSON with clientID and clientSecret that can be stored against your tenant and product for a more secure OAuth 2.0 flow. If you do not want to store the clientID and clientSecret you can alternatively use client_id=tenant=<tenantID>&product=<productID> and use dummy (or the value you set for the secret verifier env) as the value for client_secret when setting up the OAuth 2.0 flow. Additionally a idpMetadata.provider attribute is also returned which indicates the domain of your Identity Provider.

Get connections​

This endpoint can be used to retrieve SAML/OIDC connections configured for a tenant/product. This can be used to check and display the details to your customers. Look connections up by one of:

  • tenant and product: every connection of that tenant and product.
  • clientID: the connection with that client ID.
  • entityId: SAML connections for that IdP entity ID that were created without an acsUrlId.
  • entityId and acsUrlId: the SAML connection with that per-connection ACS URL, an Enterprise feature. Connections created with an acsUrlId are only found this way, never by entityId alone. Also pass acsUrlHost, the host the connection was created under; it defaults to the ACS_URL_HOST config value, and without either the request is rejected.

When more than one is given, entityId wins over clientID, which wins over tenant and product. acsUrlId and acsUrlHost are ignored without entityId; acsUrlHost with entityId but no acsUrlId is rejected.

curl -G --location 'http://localhost:5225/api/v1/sso' \
--header 'Authorization: Api-Key <Ory Polis API Key>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'tenant=ory.com' \
--data-urlencode 'product=demo'
curl -G --location 'http://localhost:5225/api/v1/sso' \
--header 'Authorization: Api-Key <Ory Polis API Key>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'clientID=<Client ID>'

Connections created without an acsUrlId, by IdP entity ID:

curl -G --location 'http://localhost:5225/api/v1/sso' \
--header 'Authorization: Api-Key <Ory Polis API Key>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'entityId=<IdP entity ID>'

A connection created with an acsUrlId. Omit acsUrlHost if ACS_URL_HOST is configured:

curl -G --location 'http://localhost:5225/api/v1/sso' \
--header 'Authorization: Api-Key <Ory Polis API Key>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'entityId=<IdP entity ID>' \
--data-urlencode 'acsUrlId=customer-a' \
--data-urlencode 'acsUrlHost=sso.example.com'

The response returns a JSON with idpMetadata.providerindicating the domain of your Identity Provider. If an empty JSON payload is returned then we do not have any connection stored for the attributes you requested.

Check whether a connection exists​

This endpoint takes the same query as Get connections and answers 204 when at least one connection matches, or 404 when none does, without returning the connections.

curl -G --location 'http://localhost:5225/api/v1/sso/exists' \
--header 'Authorization: Api-Key <Ory Polis API Key>' \
--data-urlencode 'tenant=ory.com' \
--data-urlencode 'product=demo'

Update connection​

This endpoint can be used to update an existing SSO Connection.

Identify the connection with clientID and clientSecret. Fields you leave out keep their current values.

When the update sends SAML metadata, or oidcClientId for an OIDC connection, also send the connection's tenant and product. Ory Polis uses them to check that the metadata or client ID still matches the connection, so an update can't change the identity provider's entity ID or the OIDC client ID. To change either, create a new connection.

curl --location --request PATCH 'http://localhost:5225/api/v1/sso' \
--header 'Authorization: Api-Key <Ory Polis API Key>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'clientID=<Client ID>' \
--data-urlencode 'clientSecret=<Client Secret>' \
--data-urlencode 'encodedRawMetadata=Base64(<IdP/SP metadata XML>)' \
--data-urlencode 'defaultRedirectUrl=http://localhost:3366/login/saml' \
--data-urlencode 'redirectUrl=http://localhost:3366/*' \
--data-urlencode 'redirectUrl=http://localhost:3000/*' \
--data-urlencode 'tenant=ory.com' \
--data-urlencode 'product=demo' \
--data-urlencode 'name=demo-connection' \
--data-urlencode 'description=Demo SAML connection'

Ory Polis tells a SAML update from an OIDC update by the fields in the request: encodedRawMetadata, rawMetadata or metadataUrl mark it as SAML, and oidcDiscoveryUrl or oidcMetadata mark it as OIDC. If an update sends none of these, for example when it only changes the connection's name, add isSAML=true or isOIDC=true. Without it, the request fails with 400 Missing SSO connection params.

curl --location --request PATCH 'http://localhost:5225/api/v1/sso' \
--header 'Authorization: Api-Key <Ory Polis API Key>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'clientID=<Client ID>' \
--data-urlencode 'clientSecret=<Client Secret>' \
--data-urlencode 'isSAML=true' \
--data-urlencode 'name=renamed-connection'

An OIDC connection logs in with either its discovery URL or its OpenID Provider metadata. An update with oidcDiscoveryUrl switches the connection to that URL and drops any stored metadata. An update with oidcMetadata and no oidcDiscoveryUrl merges the fields it sends into the stored metadata and drops the discovery URL. The merged metadata must still have issuer, authorization_endpoint, token_endpoint, userinfo_endpoint and jwks_uri, or the update fails with 400 and the connection stays as it was. An empty value counts as missing, so an update cannot clear a field.

Delete connections​

This endpoint can be used to delete existing connections either by tenant/product or clientID. When deleting by clientID, send the connection's client secret in the x-polis-client-secret header.

curl -X "DELETE" --location 'http://localhost:5225/api/v1/sso' \
--header 'Authorization: Api-Key <Ory Polis API Key>' \
--url-query 'tenant=ory.com' \
--url-query 'product=demo'
curl -X "DELETE" --location 'http://localhost:5225/api/v1/sso' \
--header 'Authorization: Api-Key <Ory Polis API Key>' \
--header 'x-polis-client-secret: <Client Secret>' \
--url-query 'clientID=<Client ID>'

Per-connection ACS URLs​

info

Per-connection ACS URLs and additional ACS URLs are an Enterprise feature: only the Ory Polis Enterprise License images include them. The open source images and the npm library answer 403 to a request that sets acsUrlId, acsUrlHost or additionalAcsUrls, and to a SAML response posted to /api/oauth/saml/<acsUrlId>. They also refuse to sign in through a connection that already has a per-connection or additional ACS URL, such as one an Enterprise License deployment created in a shared database.

By default, all SAML connections share a single Assertion Consumer Service (ACS) URL (samlPath). When multiple tenants use the same Identity Provider (same entity ID), Ory Polis resolves the connection by tenant and product.

Per-connection ACS URLs give each connection its own ACS endpoint, which is useful when your customers' IdPs require a unique ACS URL per app or when multiple connections share the same entity ID and you need the IdP to route responses to a specific connection.

1. Configure the default host​

Set the ACS_URL_HOST environment variable to the public hostname of your Ory Polis instance:

ACS_URL_HOST=sso.example.com

This tells Ory Polis which hostname to store on connections and to use when looking up connections from incoming SAML responses. See ACS_URL_HOST for details.

2. Create a connection with acsUrlId​

Pass acsUrlId when creating the SAML connection. The value must be 4-64 characters using letters, numbers, dots, hyphens, underscores, and tildes.

curl --location --request POST 'https://sso.example.com/api/v1/sso' \
--header 'Authorization: Api-Key <Ory Polis API Key>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'encodedRawMetadata=Base64(<IdP/SP metadata XML>)' \
--data-urlencode 'defaultRedirectUrl=https://your-app.com/sso/callback' \
--data-urlencode 'redirectUrl=https://your-app.com/*' \
--data-urlencode 'tenant=customer-a.com' \
--data-urlencode 'product=your-app' \
--data-urlencode 'acsUrlId=customer-a'

The response includes the connection's unique ACS URL in the acsUrlOverride field:

https://sso.example.com/api/oauth/saml/customer-a

Give this URL to your customer to configure as the ACS URL in their Identity Provider.

3. Handle the SAML response​

The Ory Polis Enterprise License images serve this route themselves, at /api/oauth/saml/<acsUrlId>.

Additional ACS URLs​

A connection with an acsUrlId can also accept SAML responses addressed to other URLs, for example the URLs of a proxy in front of Ory Polis. List up to 10 http(s) URLs in additionalAcsUrls when you create or update the connection:

curl --location --request PATCH 'https://sso.example.com/api/v1/sso' \
--header 'Authorization: Api-Key <Ory Polis API Key>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'clientID=<Client ID>' \
--data-urlencode 'clientSecret=<Client Secret>' \
--data-urlencode 'isSAML=true' \
--data-urlencode 'additionalAcsUrls=https://proxy.example.com/sso/customer-a' \
--data-urlencode 'additionalAcsUrls=https://proxy.example.com/sso/customer-a-legacy'
  • Ory Polis compares the response's Recipient with each URL exactly as written, so case, a trailing slash and an explicit default port must match what the IdP sends.
  • It checks the Recipient against the list only on the connection's own ACS route, /api/oauth/saml/<acsUrlId>. Responses posted to the shared ACS URL don't use the list.
  • Create and update reject a non-empty list with 400 Bad Request when the connection has no acsUrlId.
  • On update, leaving out additionalAcsUrls keeps the list, and an empty list ([] in a JSON body) removes it.

A connection created through a setup link gets an acsUrlId only when the link was created with one. The ID is stored on the link, so the link's instructions can show the ACS URL before the connection exists, and it stays the same when the link is regenerated or renewed. See Give connections their own ACS URL.

OAuth 2.0 flow​

info

OpenID Connect flow​

Ory Polis also supports the OIDC flow. By including openid in the scope param, an additional id_token is returned from the token endpoint which contains the user claims: id, email, firstName, and lastName. To enable the flow on Ory Polis, be sure to configure the keys and algorithm in OpenID configuration. If the authentication request contained nonce then it is passed unmodified to the ID Token, which the client can use to validate and mitigate replay attacks. The ID Token's polis_login_id claim is the ID of the login at Ory Polis; send the ID Token back as id_token_hint when you log the user out (see SAML SLO).

Ory Polis has been designed to abstract the underlying SAML/OIDC login flow as a pure OAuth 2.0 flow. This means it's compatible with any standard OAuth 2.0 library out there, both client-side and server-side. It is important to remember that SSO Connection is configured per customer unlike OAuth 2.0 where you can have a single OAuth app supporting logins for all customers.

Ory Polis also supports the PKCE authorization flow, so you can protect your SPAs. By default the S256 code challenge method is the only one accepted. A deployment can set OPENID_PKCE_ALLOW_PLAIN to accept plain as well, for legacy clients that cannot compute an S256 challenge. A method that Ory Polis does not implement is rejected either way.

If for any reason you need to implement the flow on your own, the steps are outlined below:

Authorize​

The OAuth flow begins with redirecting your user to the authorize URL:

https://localhost:5225/api/oauth/authorize
?response_type=code&provider=saml
&client_id=<clientID or tenant and product query params as described in the SSO connection API section above>
&redirect_uri=<redirect URL>
&state=<randomly generated state id>
  • response_type: code is the only supported type for now but maybe extended in the future
  • client_id: Use the client_id returned by the SSO connection API or use tenant=<tenantID>&product=<productID> to use the tenant and product IDs instead. Note: Please don't forget to URL encode the query parameters including client_id. See How the connection is chosen for how client_id combines with tenant and product.
  • tenant: Optionally you can use dummy as the value for client_id and specify the tenant and product custom attributes (if your OAuth 2.0 library allows it).
  • product: Should be specified if specifying tenant above
  • idp_hint: Can be used to select the Identity Provider if multiple connections match for the same tenant/product. Should point to the absolute "clientID" of the SSO Connection in Ory Polis.
  • redirect_uri: This is where the user will be taken back once the authorization flow is complete
  • state: Use a randomly generated string as the state, this will be echoed back as a query parameter when taking the user back to the redirect_uri above. You should validate the state to prevent XSRF attacks.
  • code_challenge (for PKCE flow): The code_verifier hashed with SHA-256 and base64url encoded without padding.
  • code_challenge_method (for PKCE flow): S256. By default this is the only accepted method, and a request that omits the parameter or sends any other value is rejected with an invalid_request error. Deployments that set OPENID_PKCE_ALLOW_PLAIN also accept plain.
  • nonce (for OIDC flow): String value used to associate a Client session with an ID Token, and to mitigate replay attacks. The value is passed through unmodified from the Authentication Request to the ID Token. Sufficient entropy MUST be present in the nonce values used to prevent attackers from guessing values.
  • forceAuthn (for SAML SSO Connections): If passed in with the value true, the outgoing SAML request to IdP will have the param ForceAuthn set as true forcing the user to re-authenticate even if they have an active session.
  • login_hint (Relevant for OIDC IdPs like Google): If passed in, the parameter will be forwarded in the OIDC IdP authorize request. The IdP can use this value (normally an account identifier such as an email address) as a hint to skip the account selection page.

NOTE: You can also pass the encoded tenant/product in either scope or access_type or resource (Set client_id as dummy). This will come in handy for some setups where the client_id can't be set dynamically.

How the connection is chosen​

An authorization request picks the connection that signs the user in by one of two routes:

  • By a registered client. client_id is the client ID of an SSO connection, or of an OIDC Identity Federation App (fed_oidc_...). The request signs in through that client's own connections.
  • By tenant and product. The request names a tenant and product, either as tenant and product parameters or encoded as tenant=<tenantID>&product=<productID> in client_id, scope, access_type or resource. Set client_id to dummy, to the encoded value, or to any value that is not a registered client ID, for example the name of your app when your OAuth 2.0 library requires one. A value starting with fed_oidc_ is always looked up as an Identity Federation App and fails if there is none.

The client_id of the request is the audience (aud) of the ID token that Ory Polis signs, so a request can't sign in through a connection that its client is not allowed to use. When a request names both a registered client and a tenant and product:

  • For an SSO connection's client ID, the tenant and product must be the connection's own. The login always uses that connection.
  • For an Identity Federation App, the product must be the app's product and the tenant must be one of the app's tenants. The login is then limited to the connections of that tenant, and the IdP selection page and idp_hint only offer those.
  • Otherwise Ory Polis rejects the request with HTTP 403 and shows its error page instead of redirecting to redirect_uri.
client_idTenant and productResult
dummy, encoded, or not a registered client IDRequiredSigns in through that tenant and product
An SSO connection's client IDOmitted, or the connection's ownSigns in through that connection
An SSO connection's client IDAny other tenant or productRejected
An Identity Federation App's client ID (fed_oidc_)OmittedSigns in through any of the app's tenants
An Identity Federation App's client ID (fed_oidc_)One of the app's tenants, with its productSigns in through that tenant only
An Identity Federation App's client ID (fed_oidc_)Any other tenant or productRejected

The user will be taken to the IdP based on the configured SAML/OIDC metadata. In case of any errors, we return the error, error_description and state (from original request) (see Error Response) back to the redirect_uri (redirect_uri is validated against the saml connection to prevent open redirects).

Code exchange​

Once the user logs in successfully at the IdP, IdP sends back the SAML/OIDC response to Ory Polis. For SAML, the response contains the user profile. In the case of OIDC, the response contains the authorization code that is used by Ory Polis to obtain token and userprofile from the OIDC IdP. Ory Polis generates a short lived code and stores the user profile against it. After successful authorization, the user is redirected back to the redirect_uri. The query parameters will include the code and state parameters. You should validate that the state matches the one you sent in the authorize request.

A login completes at most once​

Ory Polis keeps a short-lived session for each login, from the authorize request until the Identity Provider's response reaches the SAML ACS URL (/api/oauth/saml, or the connection's own ACS URL) or the OIDC callback (/api/oauth/oidc). The first response to arrive uses up the session, whether Ory Polis accepts it or not:

  • If Ory Polis rejects the response, for example because a signature or audience check fails or the OIDC provider returns an error such as the user canceling, the session is gone. Ory Polis usually reports the failure by redirecting the user to your redirect_uri with an error parameter.
  • Any later response for the same login, including the same response sent again, fails with a 403 error. If the Identity Provider posts twice, for example because the user submitted its form twice, only the first response can complete the login.

Retrying the callback can't recover a login. Start a new login from the authorize request instead. When your redirect_uri receives an error, send the user back to the start of your sign-in flow rather than replaying the response. The same applies when you call samlResponse and oidcAuthzResponse through the npm library.

The code can then be exchanged for a token by making the following request:

curl --request POST \
--url 'http://localhost:5225/api/oauth/token' \
--header 'content-type: application/x-www-form-urlencoded' \
--data 'grant_type=authorization_code' \
--data 'client_id=<clientID or tenant and product query params as described in the SAML connection API section above>' \
--data 'client_secret=<clientSecret or clientSecretVerifier if set (which otherwise defaults to "dummy")' \
--data 'redirect_uri=<redirect URL>' \
--data 'code=<code from the query parameter above>'
  • grant_type: authorization_code is the only supported flow, for now. We might extend this in the future
  • client_id: Use the clientID returned by the SSO connection API or use tenant=<tenantID>&product=<productID> to use the tenant and product IDs instead. Note: Please don't forget to URL encode the query parameters including client_id. For an Identity Federation OIDC app, use the app's client ID.
  • client_secret: Use the clientSecret returned by the SAML connection API or clientSecretVerifier (which defaults to "dummy") if using the tenant and product in the clientID. For an Identity Federation OIDC app, use the app's client secret.
  • redirect_uri: This is where the user will be taken back once the authorization flow is complete. Use the same redirect_uri as the previous request

In the PKCE flow, send the code_verifier in place of the client credentials:

curl --request POST \
--url 'http://localhost:5225/api/oauth/token' \
--header 'content-type: application/x-www-form-urlencoded' \
--data 'grant_type=authorization_code' \
--data 'redirect_uri=<redirect URL>' \
--data 'code=<code from the query parameter above>' \
--data 'code_verifier=<the value the code_challenge in the authorize request was derived from>'
  • code_verifier (for PKCE flow): The high-entropy string that the code_challenge was derived from. Ory Polis applies the code challenge method recorded with the authorization request and rejects the exchange when the result does not match the stored challenge. A PKCE exchange needs no client_secret, except for Identity Federation OIDC apps.

A code issued for an Identity Federation OIDC app is exchanged only with that app's own client ID and client secret, with or without PKCE. Other credentials, such as an SSO connection's client ID and secret or the clientSecretVerifier, are rejected with HTTP 401 invalid_client. See Token exchange for OIDC apps.

Ory Polis checks that the client_id of the authorization request may use the connection that signed the user in, whichever way the client authenticates. If it may not, the exchange fails with HTTP 400, the same invalid_grant response as for an expired or already used code. See How the connection is chosen.

If everything goes well you should receive a JSON response that includes the access token. This token is needed for the next step where we fetch the user profile.

The token endpoint can be called from browser applications on any origin: responses carry Access-Control-Allow-Origin: *, and a CORS preflight request is answered for POST, so the code exchange may also be sent as JSON or with the client credentials in an Authorization header. The same applies to GET requests for the discovery document at /.well-known/openid-configuration. CORS controls whether a browser sends a cross-origin request that needs a preflight and whether the page can read the response; authentication is handled exactly as described above either way, so keep client secrets out of browser code and use the PKCE flow there.

A code can be redeemed only once, and the first token request for it uses it up whether or not it succeeds. If the request fails, for example because the client_secret, code_verifier or redirect_uri is wrong, sending it again with the same code fails with a 400 Invalid code response. Fix the request and start a new login from the authorize request to get a new code.

{
"access_token": <access token>,
"token_type": "bearer",
"expires_in": 300
}

Profile request​

The short-lived access token can now be used to request the user's profile. You'll need to make the following request:

curl --request GET \
--url 'https://localhost:5225/api/oauth/userinfo' \
--header 'authorization: Bearer <access token>'

If everything goes well you should receive a JSON response with the user's profile:

{
"id": <id from the Identity Provider>,
"email": [email protected]",
"firstName": "SAML",
"lastName": "Ory Polis"
"raw": {
...
},
"requested": {
...
}
}
  • id: The identifier of the user. For a directly configured SSO connection this is the identifier the Identity Provider provided. For an Identity Federation app it is derived from the upstream connection that authenticated the user, so that two connections behind one app cannot return the same identifier for two different people. Use it as the key you store the account under.
  • logoutNameId: SAML connections only. The NameID exactly as the Identity Provider asserted it. Pass it as nameId for SAML SLO. It can differ from id, and two users can share it, so do not store an account under it.
  • upstream_sub: Identity Federation apps only. The identifier the upstream Identity Provider asserted. Two connections behind one app can assert the same value, so do not store an account under it. For SAML single logout, pass logoutNameId instead.
  • legacy_sub: Identity Federation apps only, and only while OPENID_IDFED_LEGACY_SUBJECT is true. The identifier the app returned before identifiers became connection-scoped. Use it once, to find an account you stored under the old identifier and save id in its place. Do not store it: it is not unique across the connections behind an app and the claim will be removed in a later release.
  • email: The email address of the user as provided by the Identity Provider
  • firstName: The first name of the user as provided by the Identity Provider
  • lastName: The last name of the user as provided by the Identity Provider
  • raw: This contains all claims attributes returned by the SAML provider
  • requested: This contains the tenant, product, client_id and state from the authorize request. It can be used to reconcile context on the client side if needed

SAML SLO​

SLO is a SAML flow that allows an end-user to logout of a single session and be automatically logged out of all linked sessions created during the SSO process.

The SLO flow begins with redirecting your user to the /api/logout endpoint.

https://localhost:5225/api/logout
?nameId=google-auth0-f92cc1834efc0f73e9c09
&tenant=ory.com
&product=demo
&redirectUrl=http://www.example.com/logout
  • nameId: Identifies the subject of a SAML assertion (Typically the user who is authenticated)
  • tenant: The tentant
  • product: The product
  • clientID: The client ID of the SAML connection the user signed in through. Optional when only one SAML connection for the tenant and product supports SLO. You can send clientID instead of tenant and product.
  • redirectUrl: Post logout redirect URL
  • id_token_hint: Optional. The ID Token Ory Polis issued for the login you are ending, even if it has expired. Ory Polis reads its polis_login_id claim to tie the logout to that login in its telemetry. A token Ory Polis did not sign is ignored, and the logout goes ahead without it. Like nameId, the token travels in the URL, so browser history and request logs can keep it, along with the user claims it carries. Leave it out if that is not acceptable for your deployment.

A logout request is only meaningful to the identity provider that authenticated the user. If more than one SAML connection for the tenant and product supports SLO, Ory Polis responds with 400 Bad Request unless you pass clientID. The profile returned by userinfo carries the connection's client ID in requested.idp_hint when the user picked an identity provider on the selection page, and in requested.client_id when you started the sign-in with that client ID.

IdP will send a response to a specific URL (Single Logout URL) for the logout request. You need to register this URL on the IdP /api/logout/callback to handle the response. It accepts both the HTTP-POST binding, where the LogoutResponse carries an XML signature, and the HTTP-Redirect binding, where the IdP signs the query string. On the HTTP-Redirect binding Ory Polis verifies the signature with the IdP certificates from the connection's metadata and accepts SHA-256, SHA-384 and SHA-512 signatures only. If a connection stored only the certificate's thumbprint, update it with the IdP metadata again.

Ory Polis will redirect users to redirectUrl after the successful logout.

If the logout response is unsigned or its signature does not validate, Ory Polis responds with 403 Forbidden and a message that names the problem instead of redirecting. When the cause is an algorithm the platform refuses, such as RSA-SHA1, the message asks you to configure the IdP to sign with RSA-SHA256.

Save the logoutNameId returned by userinfo or the ID token for a user, and pass it as nameId with an SLO request. It is the NameID exactly as the Identity Provider asserted it, for a directly configured SSO connection and an Identity Federation app alike, and it does not depend on what supplies id. The Identity Provider does not recognise any other value and may leave the session open.

A login from before logoutNameId existed has no such claim. For those, pass id, or upstream_sub for an Identity Federation app. Both are the NameID unless the Identity Provider sends an id attribute or the connection's subject sources name an attribute or email-hash.