# SAMLSSO with ADFS

This connects the server to Active Directory Federation Services (ADFS), Microsoft's SAML provider for a Windows domain, with [SAMLSSO](Plugin-SAMLSSO.md). People of the domain then sign in to the web interface with their Windows account, and from a machine of the domain without typing anything.

In the examples the server is `https://files.example.com/` and ADFS is `https://adfs.example.com/`.

## 1. A relying party trust in ADFS

In **AD FS Management**: **Relying Party Trusts** › **Add Relying Party Trust**, claims aware, **Enter data about the relying party manually**.

| Step of the wizard | Give |
|---|---|
| **Display name** | `CrushMFT` |
| **Configure URL** | tick **Enable support for the SAML 2.0 WebSSO protocol**, with the URL `https://files.example.com/?u=SSO_SAML&p=none` |
| **Relying party trust identifier** | `https://files.example.com/` |
| **Access control policy** | who may use it: everyone, or a group |

Afterwards open the trust's properties and check the tab **Endpoints**: one **SAML Assertion Consumer** endpoint, binding **POST**, with the URL above.

## 2. Claims

On the trust: **Edit Claim Issuance Policy** › **Add Rule**.

| Rule | Template | Give |
|---|---|---|
| the name | **Send LDAP Attributes as Claims** | attribute store **Active Directory**; **SAM-Account-Name** to the outgoing claim **Name ID** |
| the groups, if you want them from ADFS | the same template | **Token-Groups - Unqualified Names** to an outgoing claim named `group` |

The first is needed: without a Name ID the server has no user name.

## 3. Set the plugin

ADFS publishes its metadata at `https://adfs.example.com/FederationMetadata/2007-06/FederationMetadata.xml`.

| Setting | Value |
|---|---|
| **SAML Provider URL (EntityID)** | the `entityID` of the metadata, usually `http://adfs.example.com/adfs/services/trust` |
| **IDP Redirect URL (HTTP-POST)** | `https://adfs.example.com/adfs/ls/` |
| **SAML Issuer** | `https://files.example.com/`: the identifier of step 1 |
| **SAML Audience** | the same |
| **This CrushMFT server's URL** | `https://files.example.com/` |
| **Base64 encoded PEM Signing certificate** | the token-signing certificate: the `X509Certificate` block of the metadata, or the export of the certificate from **Service** › **Certificates** in ADFS, as Base-64 without the first and last line |
| **Authentication type** | `auto`. To insist on a typed password, `urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport`; to accept the Windows sign-in of the machine, `urn:federation:authentication:windows`. |

And what users get: with the groups claim, list the group names as roles and set **SAMLSSO Cache Time** to `-1`. Or use the directory lookup of the lower half, against the same Active Directory. See [what the user gets](Plugin-SAMLSSO.md#what-the-user-gets).

## 4. Try it

Open `https://files.example.com/?u=SSO_SAML&p=redirect`. The browser goes to ADFS, and comes back signed in.

## When it does not work

| What you see | Look at |
|---|---|
| ADFS shows an error page with an activity ID | the ADFS event log, **AD FS** › **Admin**. Usually the identifier in the request does not match the trust: **SAML Issuer** and the relying party trust identifier must be the same, letter for letter. |
| back at the server's login page, with a refusal | the server's log with **Debug** on. "Audience mismatch": **SAML Audience**. A signature message: the certificate is not the token-signing one, or ADFS renewed it. Messages about "NotBefore": the clocks. |
| a sign-in that worked for a year stops | ADFS replaces its token-signing certificate by itself, by default every year. Put the new one into the plugin. |
| the name is not found | the Name ID rule sends another form of the name than the directory lookup searches for. Send **SAM-Account-Name** and search by `sAMAccountName`, or send the UPN and search by `userPrincipalName`. |

## Things to know

- **Certificate rollover.** ADFS announces its next token-signing certificate in the metadata some weeks before it switches. Check the metadata before the old one ends.
- **From outside the network**, people reach ADFS through its proxy (Web Application Proxy), which shows a form. The server needs no change for that.
- **For Entra ID**, not ADFS: [SAMLSSO with Microsoft Entra](Plugin-SAMLSSO-Azure.md).

## Not tried for this page

Nothing was run against an ADFS server. The steps on the provider's side follow the earlier documentation and the provider's console as it is known; names of menus change over time. The plugin's side is from its screen and from what the plugin's file says it checks. Try the first setup with one test user and **Debug** on.
