> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tablepro.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Sign-in through your IdP

> Connect the self-hosted TablePro server to AWS IAM Identity Center, another SAML 2.0 IdP such as OneLogin, or an OpenID Connect IdP, and how long sessions last

People sign in to the portal, and through it to the Mac, with one identity provider, over SAML 2.0 or OpenID Connect. `SAML_IDP_ENTITY_ID` or `OIDC_ISSUER` picks which; set exactly one.

From every IdP, the server takes:

* **A subject that never changes**: OIDC's `sub`, or SAML's NameID in `persistent` format, up to 256 characters. The person is the IdP plus that subject.
* **An email address at every sign-in.** It never links two identities: a first sign-in whose address another account already has is refused.
* **Groups**, only when `IDP_ADMIN_GROUP_ID` is set. Members of that group are the server's admins; see [Roles](https://docs.tablepro.app/self-hosted/roles.md#server-roles). The ID is matched exactly, so use an ID that never changes, not a display name, wherever the IdP sends IDs.

Every sign-in URL is on the portal host. With `ACCOUNT_HOST=tablepro-account.example.com`:

| Value | URL |
| - | - |
| SAML start URL | `https://tablepro-account.example.com/api/auth/saml/start` |
| SAML ACS URL | `https://tablepro-account.example.com/api/auth/saml/callback` |
| SAML entity ID and audience, also the SP metadata | `https://tablepro-account.example.com/api/auth/saml/metadata` |
| OIDC redirect URI | `https://tablepro-account.example.com/api/auth/oidc/callback` |

`bootstrap` prints the ones your server uses.

## AWS IAM Identity Center

Identity Center connects an outside application over SAML 2.0 from an organization instance only, and its customer managed SAML applications are created in the console only.

**1. Add the application**

In the IAM Identity Center console, choose **Applications**, open the **Customer managed** tab, and choose **Add application**. Under **Setup preference**, choose **I have an application I want to set up**, under **Application type** choose **SAML 2.0**, then **Next**. Enter `TablePro` as the **Display name**.

**2. Download the IdP metadata**

Under **IAM Identity Center metadata**, choose **Download** beside **IAM Identity Center SAML metadata file**. Pass this file to `credentials.sh` as its second argument, and set `SAML_IDP_ENTITY_ID` to the `entityID` of its `EntityDescriptor`:

```bash theme={null}
grep -o 'entityID="[^"]*"' idp-metadata.xml | head -1
```

**3. Set the application properties**

Under **Application properties**, set **Application start URL** to `https://tablepro-account.example.com/api/auth/saml/start`, so the access portal's tile starts a sign-in the server accepts. Leave **Relay state** empty. The server does not read **Session duration**.

**4. Type the application metadata**

Under **Application metadata**, choose **Manually type your metadata values**. Set **Application ACS URL** to `https://tablepro-account.example.com/api/auth/saml/callback` and **Application SAML audience** to `https://tablepro-account.example.com/api/auth/saml/metadata`. Choose **Submit**.

**5. Map the attributes**

On the application's page, choose **Actions**, then **Edit attribute mappings**. Fill in the rows, adding each one past **Subject** with **Add new attribute mapping**, then choose **Save changes**.

| User attribute in the application | Maps to this string value or user attribute in IAM Identity Center | Format |
| - | - | - |
| `Subject` | `${user:subject}` | `persistent` |
| `email` | `${user:email}` | `unspecified` |
| `groups` | `${user:groups}` | `unspecified` |

Add `groups` only with `IDP_ADMIN_GROUP_ID`. Identity Center sends one value per group, each the group's ID. A `name` attribute is optional and names the person in the portal.

**6. Assign people**

In the **Assigned users** section, choose **Assign users**, pick the users or groups who use TablePro, and choose **Assign users**. Identity Center does not support nested groups for assignments: assign the group people are direct members of.

**7. Find the admin group's ID**

`IDP_ADMIN_GROUP_ID` is the group's ID, not its name. From the AWS CLI, with your group's display name:

```bash theme={null}
aws sso-admin list-instances --query 'Instances[0].IdentityStoreId' --output text
aws identitystore get-group-id --identity-store-id <identity store ID> \
  --alternate-identifier '{"UniqueAttribute":{"AttributePath":"displayName","AttributeValue":"TablePro admins"}}'
```

`GroupId` in the answer is the value.

> [!TIP]
>
> After `bootstrap`, its link opens the Identity Center sign-in, and signing in lands in the portal as the owner. The tile in the AWS access portal signs in too.

> [!WARNING]
>
> Identity Center sends `${user:subject}` as the person's user name. Someone whose user name changes signs in as a new person, and that sign-in is refused while their old account holds the address.

## Another SAML 2.0 IdP

The server is a SAML 2.0 Web Browser SSO service provider, SP-initiated only. Set the IdP's application up with these values:

| Setting | Value |
| - | - |
| SP entity ID and audience | `https://tablepro-account.example.com/api/auth/saml/metadata` |
| ACS URL, HTTP-POST binding | `https://tablepro-account.example.com/api/auth/saml/callback` |
| Start URL, for an IdP portal tile | `https://tablepro-account.example.com/api/auth/saml/start` |
| NameID | Format `persistent`, a value that never changes for the person |
| Attributes, by `Name` | `email`, required. `name`, optional. `groups`, one value per group, only with `IDP_ADMIN_GROUP_ID` |
| Signature | The Response or the assertion signed with SHA-256 or stronger, by an RSA key of 2048 bits or more, or ECDSA P-256, P-384 or P-521 |
| Encryption | Off. The server holds no key and refuses an encrypted assertion |

An IdP that imports service provider metadata reads it from the metadata URL.

From the IdP, the server needs its metadata file, passed to `credentials.sh`, which becomes the `saml-idp-metadata` credential. It is never fetched, so the server needs no route to the IdP. It must list an HTTP-Redirect `SingleSignOnService` at an `https` URL. Every signing certificate in it is trusted. Set `SAML_IDP_ENTITY_ID` to its `entityID`.

The server checks the signature, the Destination and Recipient against the ACS, the audience, the Issuer, InResponseTo against the request this browser started, an IssueInstant at most 90 seconds old with 180 seconds of clock skew, and that no assertion is used twice. A failure shows a sign-in error, and the server log names the check that failed.

A Response without RelayState, from a sign-in started at the IdP, is refused, and the log says to set the start URL. The ACS is reached by the browser, not the IdP, and a browser that blocks the portal's cookies cannot sign in.

### OneLogin

**1. Add the app**

Open **Applications**, choose **Add App**, search for "SAML custom connector", select **SAML Custom Connector (Advanced)**, enter `TablePro` as the **Display Name**, and save.

**2. Configuration tab**

Set **Audience (EntityID)** to `https://tablepro-account.example.com/api/auth/saml/metadata`, and both **Recipient** and **ACS (Consumer) URL** to `https://tablepro-account.example.com/api/auth/saml/callback`. **ACS (Consumer) URL Validator** takes a regular expression that matches the ACS URL, such as `^https://tablepro-account\.example\.com/api/auth/saml/callback$`. Set **SAML initiator** to **Service Provider** and **SAML nameID format** to **Persistent**.

**3. Parameters tab**

Set **NameID value** to an attribute that never changes for the person, not the email address. Add an `email` parameter with the person's email, and, with `IDP_ADMIN_GROUP_ID`, a `groups` parameter set to **User Roles** as a multi-value parameter. Select **Include in SAML assertion** on each.

**4. SSO tab**

Set **SAML Signature Algorithm** to SHA-256 or stronger. The **Issuer URL** is the value for `SAML_IDP_ENTITY_ID`. Choose **More Actions > SAML metadata** to download the metadata file for `credentials.sh`.

**5. Access tab**

Under **Roles**, give the app to the roles whose people use TablePro.

With **User Roles** as `groups`, OneLogin sends role names, so `IDP_ADMIN_GROUP_ID` is the admin role's name, and renaming that role takes admin away from its members at their next sign-in.

### Rotate the IdP's signing certificate

The server reads the metadata once, at start, and logs each trusted certificate's SHA-256 fingerprint, subject and end. Once a day, and at each start, it logs `idp certificate expiring` (WARN) in the 30 days before a trusted certificate ends, and `idp certificate expired` (ERROR) after: every sign-in it signs then fails. To rotate with no downtime:

**1. Trust the new certificate**

Add the IdP's new certificate, in PEM, as `saml-idp-certificates` in `TABLEPRO_CREDENTIALS`, and restart.

**2. Make it active at the IdP**

In Identity Center, an application holds up to two certificates and signs with the active one.

**3. Replace the metadata**

Put the metadata that names the new certificate in `saml-idp-metadata`, remove `saml-idp-certificates`, restart, then delete the old certificate at the IdP.

## OpenID Connect

Sign-in uses the authorization code flow, with PKCE and a nonce.

**1. Register a client**

Add `https://tablepro-account.example.com/api/auth/oidc/callback` as its redirect URI. A confidential client puts its secret in `OIDC_CLIENT_SECRET`; a public client takes none.

**2. Set the issuer**

`OIDC_ISSUER` is the issuer whose `/.well-known/openid-configuration` the server reads. It reads it at the first sign-in, so the server starts while the IdP is down. When the IdP names its issuer in the authorization response (RFC 9207), the server checks it.

**3. Check the scopes**

The default `OIDC_SCOPES`, `openid,email,profile,offline_access`, has the IdP send `email` and a refresh token, which most IdPs give for `offline_access`. Change it for an IdP that wants other scopes for those.

**4. Send groups, for an admin group**

`OIDC_GROUPS_CLAIM`, `groups` by default, names a top-level claim of the ID token, or of UserInfo when a refresh returns no ID token: a list of strings or one string.

The address is the `email` claim. With `email_verified: false`, a first sign-in is refused, and a later one keeps the account's old address. An IdP that sends no `email_verified` is taken at its word.

Every `UPSTREAM_REVALIDATE`, an hour by default, an app's refresh asks the IdP again with the refresh token the IdP gave at sign-in.

* **The IdP answers `invalid_grant`, or names another subject:** every app and portal session of the person ends, the team API tokens they created and the invitation links they were handed are revoked, and **Server > Members** in the portal lists them as refused by the identity provider until someone removes them or they sign in again. They keep their seat until removed.
* **The IdP cannot be reached, refuses the client, or gives an answer that fails its checks:** the refresh fails with 503 and nothing changes, so a rotated client secret signs nobody out.

### Provider notes

* **OneLogin over OIDC.** `OIDC_ISSUER` is `https://<subdomain>.onelogin.com/oidc/2`. Set `OIDC_SCOPES=openid,email,profile,groups`, without `offline_access`, which OneLogin's authorization code flow answers with an error. Set a **Refresh Token Timeout** in the app, or OneLogin sends no refresh token. For groups, set the app's Groups parameter to **User Roles**; `IDP_ADMIN_GROUP_ID` is then the admin role's name.
* **LDAP.** Run an OIDC broker over the directory, such as Keycloak's LDAP user federation or Dex's LDAP connector. A broker answers refreshes from its own session, so someone disabled only in the directory keeps access until the broker's session or refresh token ends. Keep those short.

## Sessions

| Session | Lasts |
| - | - |
| An app, with an OIDC IdP that gave a refresh token | `SESSION_MAX_AGE`, 168 hours by default |
| An app, with SAML or an OIDC IdP without a refresh token | `SESSION_MAX_AGE_WITHOUT_IDP_REFRESH`, 10 hours by default |
| The portal | `SESSION_MAX_AGE_WITHOUT_IDP_REFRESH` |
| An access token | 15 minutes, whatever ends the session |

An app's session counts from the portal sign-in that approved it. SAML has no refresh, so the server asks a SAML IdP nothing after the sign-in, and an admin group change takes effect at the person's next sign-in.

Removing someone at the IdP ends their sessions within those caps, or at the next check for an OIDC IdP that gives refresh tokens. The team API tokens they created and the invitation links they were handed stay until they are removed in the portal; see [Remove someone](https://docs.tablepro.app/self-hosted/roles.md#remove-someone).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.