# CrushOIDC

CrushOIDC puts a button on the login page: "Sign in with Microsoft", "Sign in with Google", or your organisation's own identity provider. People click it, sign in where they always sign in, and arrive in the server's web interface. The server never sees their password.

It speaks OpenID Connect, the sign-in protocol built on OAuth 2.0, and works with every provider that does: Microsoft Entra, Google, Okta, Amazon Cognito, Apple, Auth0, Keycloak and many more.

It needs an Enterprise licence: "Enterprise only feature". The plugin is set up in Preferences › [Plugins](Prefs-Plugins.md) › **CrushOIDC**. It comes with the server.

![The CrushOIDC plugin in Preferences](Plugin-CrushOIDC/screen.png)

| Step by step for | Page |
|---|---|
| Microsoft Entra ID (Azure AD) | [CrushOIDC with Microsoft Entra](Plugin-CrushOIDC-Microsoft.md) |
| Google | [CrushOIDC with Google](Plugin-CrushOIDC-Google.md) |
| Okta | [CrushOIDC with Okta](Plugin-CrushOIDC-Okta.md) |
| Amazon Cognito | [CrushOIDC with Amazon Cognito](Plugin-CrushOIDC-Cognito.md) |
| Apple | [CrushOIDC with Apple](Plugin-CrushOIDC-Apple.md) |
| giving each user their own cloud drive | [CrushOIDC: a VFS from the sign-in](Plugin-CrushOIDC-Custom-VFS.md) |

## What it can and cannot do

- **The browser only.** The sign-in happens in a browser that is sent to the provider and back. FTP and SFTP programs cannot do that; for them, see [the other ways to sign in](Security-Sign-In-Methods.md).
- **The authorization code flow.** The other flows of OpenID Connect are not offered.
- **The server must reach the provider** over HTTPS. Behind a proxy, allow the provider's addresses.

The other direction, where the server itself is the identity provider for other programs, is a different thing: [OIDC Server](Prefs-OIDC-Server.md).

## The way of a sign-in

1. The login page shows the button, with the text you chose.
2. A click sends the browser to the provider, with the server's **Client ID** and the address to come back to.
3. The person signs in at the provider, with whatever the provider demands: password, phone, key.
4. The provider sends the browser back to the server, to an address that ends in `/SSO_OIDC/`, with a code.
5. The server, by itself, exchanges the code and its **Client Secret** for the facts about the person: the **claims**, such as the email address and the groups.
6. The plugin takes one claim as the user name, checks the roles, builds the user, and lets them in.

## At the provider

Whatever the provider, you register the server there as an application and get two values back.

| The provider wants | Give |
|---|---|
| the kind of application | a web application, with a secret ("confidential") |
| the redirect address (also "callback" or "reply URL") | the address of the server as users call it, ending in `/SSO_OIDC/`: `https://files.example.com/SSO_OIDC/`. It must match exactly, to the last slash. |

| The provider gives | It goes into |
|---|---|
| a client ID | **Client ID** |
| a client secret | **Client Secret** |
| a configuration address, ending in `/.well-known/openid-configuration` | **OpenID Configuration URL** |

## The short way

1. **OpenID Configuration URL**: the provider's configuration address. Press **Fetch Configuration**: the plugin reads what the provider offers, and the suggestion lists fill.
2. **Client ID**, **Client Secret**.
3. **Scope**: `openid profile email`.
4. **Claim as Username**: `email`.
5. **Login button text**: "Sign in with Example".
6. **Import settings from CrushMFT user**: `default`, or a user you made as a template.
7. What users see: tick **Custom VFS?** and give a **Path**, with **Append username to path?** and **Create folder if it doesn't exist**. Or use roles. Without any folder a user is refused.
8. Leave **PKCE?** and **Verify ID Token?** ticked, as a new configuration has them.
9. Tick **Enabled** and save. Open the login page in a private window: the button is there.

## Settings

### Where it works

| Setting | Is | On a new server |
|---|---|---|
| **Enabled**, **Debug** | as for every plugin | off |
| **Log HTTP Request Calls** | every call to the provider is written to the log | off |
| **Replicate?** | for a cluster: sign-ins that are under way are shared with the other servers, so that the browser may come back to another server than the one it left. Described from the setting and the plugin's messages; not tried. | off |
| **Allowed Server Port**, **Allowed User Groups** | the listeners and [connection groups](Ports-Connection-Groups.md) whose login page shows the button: see [what login plugins share](Plugins.md#what-login-plugins-share) | all |

### The provider

| Setting | Is | On a new server |
|---|---|---|
| **OpenID Configuration URL**, **Fetch Configuration** | the address at which the provider describes itself. The plugin reads its other addresses from there. **Browse** picks a file in its place, for a provider that speaks OAuth 2.0 but publishes no such description: a small JSON file with at least `authorization_endpoint` and `token_endpoint`. | empty |
| **Client ID**, **Client Secret** | from the registration. "Error: Invalid Client ID! The Client ID is missing." | empty |
| **.p8 key**, **Team ID**, **Key ID** | only for Apple, in place of a secret: [CrushOIDC with Apple](Plugin-CrushOIDC-Apple.md) | |
| **Authorization URL** | the address the browser is sent to, built from parts in braces. Change it only when a provider needs something extra. | `{authorization_endpoint}?client_id={oidc_client_id}&response_type=code&scope={oidc_scope}&redirect_uri={oidc_redirect_url}&state={oidc_state}` |
| **Scope**, **Scope Suggestions** | what the server asks to learn about the person. `openid` is needed; `profile` and `email` bring name and address. The suggestions are the scopes the provider said it has. | `openid profile email` |
| **PKCE?** | adds a proof to the exchange that the server finishing the sign-in is the one that started it. Leave it on unless the provider cannot do it. | on |
| **Verify ID Token?** | checks the signature of what the provider sent against the provider's public keys. It needs the provider's description to name its keys (`jwks_uri`). Leave it on. | on |
| **Reject logins if email is unverified** | refuses people whose email address the provider has not confirmed, when the user name is an email address | on |
| **Get Refresh Token?** | asks the provider for a lasting token too, by adding `access_type=offline&prompt=consent` to the address. Needed only to reach the person's cloud storage: [a VFS from the sign-in](Plugin-CrushOIDC-Custom-VFS.md). | off |
| **Check User Endpoint URL?**, **User Endpoint URL** | after the sign-in, also asks the provider's user address for more facts about the person | off, `{userinfo_endpoint}` |
| **Revocation Endpoint URL** | where tokens are handed back. A lasting token is handed back when the user's session on the server ends. | `{revocation_endpoint}` |
| **End Session URL** | the provider's sign-out address, for signing out there too: see [signing out](#signing-out) | `{end_session_endpoint}` |

The parts in braces of the **Authorization URL**: `{authorization_endpoint}` from the provider's description, `{oidc_client_id}` and `{oidc_scope}` from the fields above, `{oidc_redirect_url}` the server's own return address, and `{oidc_state}` a value the server makes up for each sign-in and checks on return, so that nobody can slip in a sign-in that did not start here.

### Who the user is

| Setting | Is | On a new server |
|---|---|---|
| **Claim as Username**, **Claim Suggestions** | the claim that becomes the user name: usually `email`, or `preferred_username`, or `sub`. If the provider does not send it, the sign-in fails: "Authentication failed! Missing the OIDC username!" | `email` |
| **Remove email suffix from username** | `jdoe@example.com` becomes `jdoe` | off |
| **Username matching** | the names that are let in. `*` is all. Several patterns, separated by commas. `*@example.com` lets in one organisation, which matters with providers where anybody can have an account, such as Google. | `*` |
| **Allowed Email Domains** | the same idea, by the domain of the email address | empty |
| **Reserved User Names** | names nobody may arrive as through this plugin, such as those of your administrators | empty |
| **Skip OTP processing** | the server's own second factor is not asked of these users. The provider has its own. | off |
| **Login button text** | the text of the button | "OIDC login" |
| **Key Mappings (IDP -> CrushMFT)** | copies claims into settings of the user: the claim's name, and the user setting it goes to. **Add Key Mapping**, **Edit Selected**, **Remove Selected**. | none |

### What the user gets

| Setting | Is | On a new server |
|---|---|---|
| **OIDC only used for Authentication (User manager then defines user's access.)** | each person also exists in the User Manager, under the name the claim gives, with folders and settings like any user. The provider only proves who they are. | off |
| **Template Username** | a user of the User Manager whose settings **and folders** every person gets. It must exist. | empty |
| **Import settings from CrushMFT user** | a user whose settings, without the folders, every person gets | `default` |
| **OAuth Roles** | settings and folders by group: see below | none |
| **Custom VFS?** with **Path**, **Append username to path?**, **Create folder if it doesn't exist** | a folder, or one per person, on the server's disk or anywhere the server can reach. **Privs** are the rights in it: see [the permissions block](Plugins.md#the-permissions-block). | on, with no path |

A person needs at least one folder, from the template, a role or **Custom VFS?**. Without one the sign-in is refused.

## Roles

**OAuth Roles** does two things: it limits who may sign in, and it gives groups of people different settings.

A role is a line: a condition on a claim, and after a colon the template user for those who meet it.

```text
groups=FileTransfer : oidc_staff
```

| Line | Lets in, with the settings and folders of the user after the colon |
|---|---|
| `groups=FileTransfer : oidc_staff` | people whose claim `groups` is, or holds, `FileTransfer` |
| `groups=*Transfer* : oidc_staff` | a group whose name holds "Transfer" |
| `groups=REGEX:.*Transfer$ : oidc_staff` | a group whose name fits the pattern |
| `groups=FileTransfer,department=Finance : oidc_finance` | both conditions |
| `groups=FileTransfer` | those people, with no template of their own |

"Leave blank for all users." Once there is a role, somebody who meets none is refused: "Authentication failed! No matching role line!" **Move Up** and **Move Down** set the order.

The template user must exist in the User Manager.

## Signing out

Signing out of the server does not sign anybody out of the provider. To do that too, send the browser to the provider's sign-out address at logout.

**End Session URL** builds that address. For most providers:

```text
{end_session_endpoint}?id_token_hint={id_token}&post_logout_redirect_uri=https%3A%2F%2Ffiles.example.com%2F
```

Then, on the template user, set one of two [customizations](Users-WebInterface-Customizations.md#branding--chrome) to `{user_crushOIDC_end_session_url}`: **Redirect to this location after logout**, or **URL to open in popup on logout**.

The return address must be registered at the provider as a sign-out address, or the provider refuses.

## Several providers

Each [configuration](Prefs-Plugins.md#several-configurations-of-one-plugin) is a provider and a button. A login page can show "Sign in with Microsoft" and "Sign in with Google" side by side; **Allowed Server Port** puts a button on one listener only.

## With a DMZ

The browser talks to the DMZ server, but the check is done by the internal server. The DMZ server needs the same configuration of the plugin as far as the button and the way out go: the configuration's name, **OpenID Configuration URL**, **Client ID**, **Authorization URL**, **Scope**, **Get Refresh Token?** and **Login button text**. Everything about users stays on the internal server.

## Things to know

- **The redirect address must fit exactly.** Most first failures are a missing slash, `http` for `https`, or a host name that differs from the one users type. The provider's error page says so.
- **Behind a balancer or proxy**, the server must know the name and protocol users call it by, or it builds the wrong return address: see [a load balancer in front](HA-Load-Balancer.md).
- **If the sign-in works but ends on the login page**, look at **HTTP Redirect Base** in [Preferences, Misc](Prefs-Misc.md): earlier versions needed it emptied for this plugin.
- **The password field stays.** Local users and administrators still sign in with their passwords. To offer only the button, change the [login page](Prefs-WebInterface-Login-Studio.md).
- **A name is a claim.** If the provider lets people choose their own email address or display name, do not use that claim as the user name. Use a claim the provider controls, and **Reject logins if email is unverified**.
- **Programs.** For scripts that should sign in without a person, see [tokens](Security-Roles-Tokens.md) and [the API](API-Authentication.md).

## Not tried for this page

No provider was connected to the test server. The page is written from the plugin's screen, from what the plugin's file says it does, and from the earlier documentation.
