﻿# Authentication options

> Two settings in appsettings.json decide how users sign in:

Source: https://workwise-solutions.net/docs/installation/authentication/ · Language: en · Hungarian version: https://workwise-solutions.net/hu/docs/installation/authentication/

Two settings in `appsettings.json` decide how users sign in:

- `UserSettings.UserStore`: **where users and groups come from**: `Local`, `ActiveDirectory`, `LDAP` or `AzureAD` (Microsoft Entra ID).
- `LoginSettings.AuthType`: **how they sign in**: `Local`, `ActiveDirectory`, `AppleConnect` or `OAuth`.

| User store | Possible login types |
|---|---|
| Local | Local, OAuth |
| ActiveDirectory (Windows only) | ActiveDirectory |
| LDAP | AppleConnect, OAuth |
| AzureAD (Microsoft Entra ID) | OAuth |

With any of them, [external users](https://workwise-solutions.net/docs/features/user-management/#external-users-and-groups-külső-felhasználók-külső-csoportok) can also sign in with **Bejelentkezés külső felhasználóként**.

![Sign-in types and user stores](https://workwise-solutions.net/docs/images/diagram-authentication-en.png)
*The allowed combinations of sign-in type and user store, with directory users, external users and API clients.*

## Local (default)

Users and groups are stored in the application's database and managed on **Felhasználók** and **Csoportok**. On a new installation the sign-in page asks for the first administrator ([Getting started](https://workwise-solutions.net/docs/getting-started/)). Users can reset their password by e-mail.

## Active Directory

`UserStore` and `AuthType` both `ActiveDirectory`. Windows only: the application refuses to start with it elsewhere. The server must be domain-joined; under IIS enable Anonymous and Windows Authentication ([Windows (IIS)](https://workwise-solutions.net/docs/installation/windows-iis/)).

| Setting (`UserSettings.ADSettings`) | Meaning |
|---|---|
| `RootDomain` | LDAP path of the root container, for example `OU=Sales,DC=YourCompany,DC=com`; empty = the domain of the service account |
| `SubDomains` | Sub-domains of a forest; discovered when empty |
| `Username`, `Password`, `AuthenticationType` | Optional account for the queries |
| `AdminUsers`, `AdminGroups` | SAM names of Super Admins, `DOMAIN\\User` for other domains |
| `AdQueryTimeout` | Query timeout in seconds |
| `DomainNameAliases` | When users sign in with a different domain name than the domain's own |

`LoginSettings.ADSettings.NegotiateLogin` (default `true`) tries integrated Windows sign-in first; users can also type their user name and password.

## LDAP

`UserStore: LDAP`. Users and groups are read from an LDAP server (`UserSettings.LdapSettings`): `Host`, `Port` (389), `IsSecure` (LDAPS), `LdapRoot`, an optional bind `User` and `Password`, `AdminUsers` and `AdminGroups`, `CacheGroupsOfUserFor`, and the **flavour**:

- `ActiveDirectory`: AD attribute names over LDAP;
- `Apple`: Apple Open Directory;
- `Custom`: define the object classes and attribute names in `CustomLdapFlavor` (user ID, user name, display name, group ID and name, member attribute, e-mail, user and group roots, extra properties).

Groups are searched recursively. Sign in with `AuthType: AppleConnect` (`LoginSettings.AppleConnectSettings`: auth and validate URLs, app ID and key, shared secret, identity cookie name; an LDAP form is offered too) or with OAuth.

## Microsoft Entra ID

`UserStore: AzureAD` and `AuthType: OAuth` with the Microsoft provider. `UserSettings.AzureADSettings`: `TenantId`, `ClientId`, `ClientSecret` of an app registration that can read users and groups, `AdminUsers` (e-mail addresses), `AdminGroups` (group names), and `IssuerEmail` for B2C tenants with federated accounts.

## OAuth

`AuthType: OAuth`. The sign-in page shows one **Bejelentkezés** button that redirects to the provider. `LoginSettings.OAuthSettings.OAuthType`:

| Provider | Settings |
|---|---|
| `Okta` | `OktaDomain`, `AppId`, `AppSecret`, optional `IssuerUrl` |
| `Google` | `AppId`, `AppSecret`, `LoginHint` |
| `Microsoft` | `TenantId`, `AppId`, `AppSecret`, optional custom endpoints |
| `Custom` | Any provider with the Authorization Code flow: `AuthorizationEndpoint`, `TokenEndpoint`, `AppId`, `AppSecret`, and how to get the e-mail and name (`IdToken` with claim names, or `OpenId` with an endpoint). Redirect URL: `https://<address>/api/account/oauth/callback/custom` |

`OAuthLoginTimeout` limits how long a sign-in may take. OAuth does not work with `CacheSettings.Type: None`, and with several servers needs a shared cache.

## Permissions with a directory

With AD, LDAP or Entra ID a profile is created at a user's first sign-in. Users and groups in `AdminUsers`/`AdminGroups` become Super Admins; other users start with *Public*. Super Admins set application permissions on **Profilok**, and workspace roles can be given to directory users and groups ([User management](https://workwise-solutions.net/docs/features/user-management/#profiles-profilok)).

## Personal access tokens

Independent of the login type, API clients authenticate with personal access tokens signed by `LoginSettings.JwtAuthenticationSettings` ([Personal access tokens](https://workwise-solutions.net/docs/features/personal-access-tokens/)).
