# Single Sign-On and SCIM

On the Business plan a team can let its people sign in through the team's own identity provider (Okta, Microsoft Entra ID, Google Workspace, OneLogin, Keycloak, or anything that speaks
**OpenID Connect** or **SAML 2.0**), make that the only way into the team, and have the provider create, change and remove people and their roles automatically with **SCIM 2.0**.
Only the team's **owner** can change these settings (Settings → Teams → your team).

## Set it up

1. **Create an application at your provider** of type "OpenID Connect, web application" (authorization code flow). Give it the **Redirect URI** shown on the team page.
   The provider must sign ID tokens with **RS256** (the default almost everywhere) and include the `email` and `email_verified` claims (scopes `openid email profile`).
2. **Enter the issuer, client ID and client secret** on the team page. Tailcove reads the provider's `/.well-known/openid-configuration`, and refuses an issuer that does not answer for itself.
3. **Verify your domain.** Add each email domain your people use (for example `example.com`), put the TXT record Tailcove shows at `_tailcove-challenge.example.com`, and press Verify.
   A domain belongs to one team at a time. Tailcove only trusts an email address on a domain you have proved you own: without that, anyone running an identity provider could claim to be anyone.
4. **Turn sign-in on.** People now use **Sign in with SSO** on the login page: they type their work email, Tailcove finds the team by the verified domain and sends them to your provider.

## Who gets in

- A person your provider already identified once (by its `sub`) is that person, even if their email changes later.
- Otherwise the address must be on one of your verified domains.
- If an account with that address already exists, it is linked **only if it is already a member of your team** and its email is verified. A provider's say-so never hands over an account that is not yours.
- With **just-in-time sign-up** on, a person with no account gets one, with a verified email, no password, and the team's **default role**. With it off they have to be invited first.
- SSO sign-in counts as the second factor: Tailcove does not ask for a code on top, because your provider does that.

## Sign in with SAML

A team uses one protocol at a time. If your provider speaks SAML 2.0 and not OpenID Connect (or you simply prefer it), choose **SAML** in the single sign-on settings instead of following the OpenID Connect steps above.
Everything after the provider is the same: domain verification, who gets in, enforcement and SCIM.

### What to give your provider

Create a SAML application (sometimes called a "custom SAML app" or "SAML 2.0 web app") and fill it in with the values shown on the team page. They belong to your team, so they differ from team to team:

| Setting at your provider | Value |
| --- | --- |
| Entity ID (also called Audience or SP entity ID) | `https://tailcove.dev/sso/saml/<your-team>/metadata` |
| ACS URL (Assertion Consumer Service, also called Reply URL or Single sign-on URL) | `https://tailcove.dev/sso/saml/<your-team>/acs`, with the **HTTP-POST** binding |
| NameID format | **Email address** |
| Signing | Sign the **assertion** (or the whole response) with RSA-SHA256 |

If your provider can import a service provider's metadata, give it the **metadata URL** (the same address as the Entity ID) and it fills these in itself. Tailcove does not sign its sign-in requests, so leave "requests are signed" off.
The metadata address is public and holds nothing secret.

### What to paste back

Either of these, on the team page:

- **The provider's metadata XML.** Download the metadata file from your provider and paste its contents. Tailcove reads the entity ID, the sign-in address (the HTTP-Redirect service) and the signing certificates from it.
  Tailcove does not fetch anything from an address for you, and it refuses a file with a DOCTYPE or one that lists several providers (a federation file): paste the single provider's own entity.
- **Or the three values by hand:** the provider's **entity ID** (issuer), its **sign-in URL** (single sign-on URL, `https` only) and the **X.509 certificate** it signs with. The certificate can be pasted as PEM or as the bare base64 text most providers show.

When the provider replaces its signing certificate, paste the new metadata again. A file that carries both the old and the new certificate keeps sign-in working during the change.
Saving the same provider again keeps your settings. Saving a **different provider** (or switching between OpenID Connect and SAML) switches sign-in and enforcement off, because the ids the old provider gave your people mean nothing to the new one; turn them on again once you have signed in through it.

### The email address

Tailcove needs the person's email address, and finds it in this order: the attribute you name under "Email attribute" (if you set one), then a NameID that is an email address, then the attributes most providers use (`email`, `mail`, `emailaddress`, the Microsoft claim `.../claims/emailaddress`, and the LDAP `mail` OID).
If your provider sends an opaque, persistent NameID, release the address as an attribute. If it sends none, sign-in is refused with a message saying so. The name shown in Tailcove comes from `displayName` (or `name`) when the provider sends one.

### What is checked

Every sign-in answer is checked before anyone is let in:

- It is **signed** (the assertion, the response or both) with a certificate you saved. A certificate that only travels inside the message is never trusted.
- It is meant for **your team's** service: the audience, the destination and the recipient all name your Entity ID and ACS URL, and it comes from your provider's entity ID.
- It is **valid now**: not expired and not early (a couple of minutes of clock difference are tolerated).
- It answers **a sign-in this browser started**. Tailcove remembers each attempt for ten minutes, uses it once, and ties it to the browser with a short-lived cookie that is only sent to the SAML addresses; an answer that arrives in another browser is refused.
- It has **not been seen before**: a replayed assertion is refused.
- It has exactly one assertion, and the signature covers it.

Anything else is turned away with a general message, and the detail goes to Tailcove's own log, not to the person at the keyboard.

### What is not supported

- **Encrypted assertions.** Ask your provider to leave assertions unencrypted (the connection is https and the assertion is signed).
- **Single logout.** Signing out of Tailcove does not sign out of your provider, and the reverse.
- **Sign-in started at the provider** (IdP-initiated, the tile on the provider's app page). Start from Tailcove's "Sign in with SSO" instead; the answer has to belong to a request Tailcove made.
- **SHA-1 signatures.** RSA-SHA256 or stronger only.
- Signed sign-in requests from Tailcove, and metadata fetched from a web address.

### The rest works as with OpenID Connect

- The address must be on a [verified domain](#set-it-up) (step 3 above); a verified domain is what makes an address trustworthy.
- An existing account is linked only if it is already a member of your team and its email is verified. A person already tied to your provider by their NameID stays that person when their email changes.
- **Just-in-time sign-up**, the default role, **enforcement** (and its safeguard of signing in once first), the audit log entry `auth.sso_login` (it names the protocol) and **SCIM provisioning** behave exactly as described for OpenID Connect.
- Who is let in is decided by Tailcove's rules, never by what the provider's message asks for: an owner is never made by sign-in.

## Enforce single sign-on

With **Enforce** on, a session that did not come through your provider is not let into the team, whatever else it proved (password, passkey, GitHub or Google). The same person still reaches their other teams the usual way.
You can only turn it on after you have signed in once through SSO yourself, so a broken setup cannot lock you out on the spot.
If your provider ever stops working while it is enforced, someone with shell access runs `php artisan tailcove:team-sso-disable <team>`, which turns enforcement and sign-in off (it is recorded in the audit log).

## SCIM provisioning

On the team page, generate a **SCIM token** and give your provider the **base URL** (`https://tailcove.dev/api/scim/v2`) and the token as a bearer token. The token is shown once; Tailcove keeps only a hash. Revoke or regenerate it at any time.

| Resource | Supported |
| --- | --- |
| `/Users` | list, filter `userName eq` and `externalId eq`, get, create, replace, patch, delete |
| `/Groups` | list, filter `displayName eq`, get, create, replace, patch (add, remove and replace members, rename), delete |
| `/ServiceProviderConfig`, `/ResourceTypes`, `/Schemas` | yes |

What provisioning does, and what it never does:

- **Create** a user: only for an address on a verified domain. A new person gets an account (verified email, no password) and a membership; an existing account joins your team and keeps its password and its other teams.
- **Deactivate or delete** a user: they leave your team and the API tokens they made for it stop working, and they can no longer sign in through SSO. Their Tailcove account is **never deleted**, because it may belong to other teams.
  Delete keeps the record, inactive, so the person cannot come back just in time.
- **Roles** come from groups. Under "Group to role" map a group name to a role; a person gets the best role of the groups they are in (admin, then member, then viewer, then billing), else the default role.
  Changing the mapping changes roles for everyone provisioned. **Owner is never given by SCIM, and an owner is never changed or removed by it**; change owners in Tailcove.
- An email address changes only inside your verified domains and never onto another account.

Every provisioning action is written to the [audit log](https://tailcove.dev/docs/team-security) (`scim.*`), and so are sign-ins (`auth.sso_login`) and every change to these settings.

## Limits and notes

- OpenID Connect and SAML 2.0. SAML does not support encrypted assertions, single logout, sign-in started at the provider or SHA-1 signatures (see above).
- One provider, and so one protocol, per team.
- Bulk operations, sorting and ETags are not supported (the ServiceProviderConfig says so).
- Provider sign-in, discovery and key requests go through Tailcove's outbound-URL guard like webhooks do: https only, public addresses only.
