Authentication sources: Local, LDAP, Active Directory, custom
Every Genie user has an authentication source: the name of the system that checks their password.
Local (Genie’s own encrypted password store) is built in and is the default. A host project can
register more sources by name, such as Ldap, MicrosoftAD or Authentik, and assign them to users one by one.
Sources can be mixed: one deployment can have local service accounts, staff in Active Directory, and
contractors in a second LDAP directory.
How a login flows through a source
Section titled “How a login flows through a source”POST /api/v1/auth/login (see Identity) runs these steps:
- Find the Genie user by username or email. Unknown and deleted users fail the same way, with timing equalized, whatever the source.
- Apply the web-login gates and the lockout check.
- Resolve the user’s source by name and call its handler with the typed password:
- Success: continue.
- Failed (wrong password): counts towards
MaxInvalidLoginAttempts/ lockout, like a local failure. - Unavailable (directory down, TLS error, misconfiguration): the login is refused with the same generic message and the error is logged, but it does not count towards lockout, so an outage can’t lock everybody out.
- No source of that name is registered: refused with the generic message, and the reason is logged.
- MFA, if enabled for the user. MFA works for directory users too.
- Password expiry. This applies only to Local users, because a directory enforces its own policy.
- Issue the session/tokens.
Directory users have no Genie-held password. Because of that:
- Change password / password reset are refused for non-Local users (
400: “This account signs in through ‘Ldap’. Change the password in that directory.”). - On the Users admin form, the Password field is hidden and not required when a non-Local source is selected, and the insert-time password-policy check is skipped for such users.
Assigning a source to a user
Section titled “Assigning a source to a user”The Users management view (/form/users) has an Authentication Source dropdown. It lists Local
plus every source registered in the host. Leaving it empty stores NULL, which means Local.
You can also set it in SQL, for example to move a batch of users onto AD:
-- SQL ServerUPDATE [Identity].[Users] SET AuthenticationSource = 'MicrosoftAD'WHERE Email LIKE '%@corp.example.com';
-- PostgreSQLUPDATE "Identity"."Users" SET "AuthenticationSource" = 'MicrosoftAD'WHERE "Email" LIKE '%@corp.example.com';The login name sent to the directory is the Genie UserName by default (LoginIdentifier: Email
sends the email instead). Make sure it matches the directory account, for example the
sAMAccountName for AD.
Built-in: LDAP and Active Directory
Section titled “Built-in: LDAP and Active Directory”One handler covers both, built on System.DirectoryServices.Protocols (Windows, Linux and macOS; on
Linux the container needs libldap). It finds the identity to bind as in one of three ways, and the first one configured wins:
| Mode | Set | Binds as |
|---|---|---|
| Search, then bind | SearchBase (+ SearchFilter, optional ServiceAccountDn/ServiceAccountPassword) |
the single entry the filter finds; zero or several matches are a failed login |
| Direct bind (template) | BindDnFormat |
e.g. uid={username},ou=people,dc=example,dc=org or {username}@corp.example.com |
| Direct bind (UPN) | Domain |
{username}@{Domain}, the simplest AD setup |
Placeholders are {username} and {email}. Values are escaped (RFC 4515 in filters, RFC 4514 in DN
templates), so a username like * or a,b=c cannot inject into the query. An empty password is
always rejected before reaching the directory: an LDAP simple bind with an empty password is an
unauthenticated bind that many servers report as success.
Options (LdapAuthenticationSourceOptions)
Section titled “Options (LdapAuthenticationSourceOptions)”| Key | Default | Meaning |
|---|---|---|
Server |
— (required) | Directory host, e.g. ldap.example.org, dc01.corp.example.com |
Port |
0 → 636 with SSL, else 389 |
TCP port |
UseSsl |
true |
LDAPS. Keep it on: the bind sends the password. |
UseStartTls |
false |
Upgrade a plain 389 connection (used only when UseSsl is false) |
TimeoutSeconds |
10 |
Connect/operation timeout |
LoginIdentifier |
UserName |
UserName or Email: which Genie attribute is sent |
Domain |
— | AD domain for UPN binds |
BindDnFormat |
— | Direct-bind template |
SearchBase |
— | Root of the search, which turns on search-then-bind |
SearchFilter |
(uid={username}); AD preset: (&(objectClass=user)(sAMAccountName={username})) |
Search filter template |
ServiceAccountDn / ServiceAccountPassword |
— (anonymous search) | Account used for the search. Keep the password in user-secrets or environment variables. |
AddActiveDirectory / Type: "ActiveDirectory" is the same handler with the AD search filter preset.
Example: Microsoft Active Directory (UPN bind)
Section titled “Example: Microsoft Active Directory (UPN bind)”The simplest AD setup has no service account and binds as ann@corp.example.com:
using Genie.Engine;
builder.Services.AddGenieApp(genie => genie .LoadFromConfiguration(builder.Configuration) .ConfigureAuth(auth => auth .AddActiveDirectory(ad => { ad.Server = "dc01.corp.example.com"; ad.Domain = "corp.example.com"; })));Example: Active Directory with search-then-bind
Section titled “Example: Active Directory with search-then-bind”Use this when the login name isn’t the UPN prefix, or when users must sit in a particular OU or group:
{ "Genie": { "Auth": { "Sources": { "MicrosoftAD": { "Type": "ActiveDirectory", "Server": "dc01.corp.example.com", "SearchBase": "OU=Staff,DC=corp,DC=example,DC=com", // Only members of GenieUsers may sign in: "SearchFilter": "(&(objectClass=user)(sAMAccountName={username})(memberOf=CN=GenieUsers,OU=Groups,DC=corp,DC=example,DC=com))", "ServiceAccountDn": "CN=svc-genie,OU=Service,DC=corp,DC=example,DC=com" // ServiceAccountPassword → environment: Genie__Auth__Sources__MicrosoftAD__ServiceAccountPassword } } } }}Example: OpenLDAP / generic LDAP
Section titled “Example: OpenLDAP / generic LDAP”{ "Genie": { "Auth": { "Sources": { "Ldap": { "Type": "Ldap", "Server": "ldap.example.org", "BindDnFormat": "uid={username},ou=people,dc=example,dc=org" } } } }}Example: Authentik (through its LDAP outpost)
Section titled “Example: Authentik (through its LDAP outpost)”Authentik is an identity provider, and its LDAP outpost exposes the users as an LDAP directory. Point an LDAP source at it, using any name you like:
.ConfigureAuth(auth => auth .AddLdap("Authentik", o => { o.Server = "authentik-ldap.example.org"; o.SearchBase = "ou=users,dc=ldap,dc=goauthentik,dc=io"; o.SearchFilter = "(cn={username})"; o.ServiceAccountDn = "cn=genie-bind,ou=users,dc=ldap,dc=goauthentik,dc=io"; o.ServiceAccountPassword = builder.Configuration["Authentik:BindPassword"]; }))Then set those users’ Authentication Source to Authentik.
Several directories at once
Section titled “Several directories at once”Each source is a named options instance, so one handler type can back many sources:
.ConfigureAuth(auth => auth .AddActiveDirectory("CorpAD", o => { o.Server = "dc01.corp.example.com"; o.Domain = "corp.example.com"; }) .AddActiveDirectory("SubsidiaryAD", o => { o.Server = "dc.sub.example.net"; o.Domain = "sub.example.net"; }) .AddLdap("Partners", o => { o.Server = "ldap.partners.example.org"; o.BindDnFormat = "uid={username},ou=partners,dc=example,dc=org"; }))Custom sources
Section titled “Custom sources”Implement IAuthenticationSourceHandler (Genie.Engine.Core.Abstractions) and register it under a name.
Handlers are resolved per request (scoped), so they can take HttpClient, DbContext or
other scoped services.
using Genie.Engine.Core.Abstractions;using Microsoft.Extensions.Options;
public sealed class CorpSsoOptions{ public string TokenEndpoint { get; set; } = ""; public string ClientId { get; set; } = ""; public string ClientSecret { get; set; } = "";}
/// Validates the password with the IdP's resource-owner password grant.public sealed class CorpSsoHandler(IHttpClientFactory http, IOptionsMonitor<CorpSsoOptions> options) : IAuthenticationSourceHandler{ public async Task<CredentialValidationResult> ValidateCredentialsAsync( CredentialValidationContext context, CancellationToken ct = default) { var o = options.Get(context.SourceName); // per-source settings try { using var response = await http.CreateClient().PostAsync(o.TokenEndpoint, new FormUrlEncodedContent(new Dictionary<string, string> { ["grant_type"] = "password", ["client_id"] = o.ClientId, ["client_secret"] = o.ClientSecret, ["username"] = context.User.UserName!, ["password"] = context.Password, }), ct);
return response.IsSuccessStatusCode ? CredentialValidationResult.Success() : CredentialValidationResult.Failed($"IdP answered {(int)response.StatusCode}"); // counts towards lockout } catch (HttpRequestException ex) { return CredentialValidationResult.Unavailable(ex.Message); // does not } }}// Program.cs: name it and configure it in the host.ConfigureAuth(auth => auth .AddAuthenticationSource<CorpSsoHandler, CorpSsoOptions>("CorpSso", o => builder.Configuration.GetSection("Genie:Auth:Sources:CorpSso").Bind(o)))A Genie:Auth:Sources:{Name} entry without a Type (or with "Type": "Custom") is ignored by the
engine. It is just a convenient place to keep your handler’s settings, as above. An unknown Type fails at startup.
Handler rules:
- Never throw for a wrong password. Return
Failed(...). ReturnUnavailable(...)for infrastructure problems, so they don’t lock users out. FailureReasonis logged only and never shown to the caller, who always sees the generic message.- The handler receives the already-resolved
ApplicationUser. Use whichever attribute (UserName,Email) your system knows the user by. - Registering a source named
Localreplaces the built-in password check. Do this only on purpose.
Builder API reference (GenieAuthBuilder)
Section titled “Builder API reference (GenieAuthBuilder)”| Method | Registers |
|---|---|
AddLdap(string name = "Ldap", Action<LdapAuthenticationSourceOptions>? configure = null) |
LDAP source |
AddActiveDirectory(string name = "MicrosoftAD", Action<LdapAuthenticationSourceOptions>? configure = null) |
LDAP source with AD defaults |
AddAuthenticationSource<THandler>(string name, Action<IServiceCollection>? configureServices = null) |
Custom handler; add any services it needs |
AddAuthenticationSource<THandler, TOptions>(string name, Action<TOptions> configure) |
Custom handler + named options |
Config (Genie:Auth:Sources:{Name}) and code compose. Config is loaded first, then the code runs, and a
later registration of the same name wins.
Upgrading an existing database
Section titled “Upgrading an existing database”The column Identity.Users.AuthenticationSourceName (non-null, always 'local') is now
AuthenticationSource (nullable). Pre-release, the engine ships no migration of its own, so in
your host’s EF migration rename the column rather than letting EF drop and re-add it:
migrationBuilder.RenameColumn( name: "AuthenticationSourceName", schema: "Identity", table: "Users", newName: "AuthenticationSource");migrationBuilder.AlterColumn<string>( name: "AuthenticationSource", schema: "Identity", table: "Users", type: "nvarchar(max)", nullable: true, oldClrType: typeof(string), oldType: "nvarchar(max)");Existing 'local' values keep working, because names are case-insensitive.
Related
Section titled “Related”- Identity: JWT, MFA, sessions: the rest of the login pipeline.
- Password encryption: how the Local source stores passwords.
- Configuration: the
Genie:Authsection.
Copyright © 2026 Orbyn Technologies. All rights reserved.