![]() |
VOOZH | about |
dotnet add package PrimusSaaS.Identity.Broker --version 2.6.0
NuGet\Install-Package PrimusSaaS.Identity.Broker -Version 2.6.0
<PackageReference Include="PrimusSaaS.Identity.Broker" Version="2.6.0" />
<PackageVersion Include="PrimusSaaS.Identity.Broker" Version="2.6.0" />Directory.Packages.props
<PackageReference Include="PrimusSaaS.Identity.Broker" />Project file
paket add PrimusSaaS.Identity.Broker --version 2.6.0
#r "nuget: PrimusSaaS.Identity.Broker, 2.6.0"
#:package PrimusSaaS.Identity.Broker@2.6.0
#addin nuget:?package=PrimusSaaS.Identity.Broker&version=2.6.0Install as a Cake Addin
#tool nuget:?package=PrimusSaaS.Identity.Broker&version=2.6.0Install as a Cake Tool
Server-side authentication middleware for ASP.NET Core browser apps.
This package implements a Backend-for-Frontend pattern for applications that want secure cookie sessions instead of storing access tokens in the browser. It handles local login, OIDC and SAML sign-in, MFA, and session lifecycle on the server side.
WithUserCheck(...) and WithAutoProvision(...)This package is not:
If your APIs already receive JWTs and only need validation, use PrimusSaaS.Identity.Validator instead.
dotnet add package PrimusSaaS.Identity.Broker
Tell the broker how to look up or provision your users.
// In Program.cs
builder.Services.AddPrimusAuthBroker(builder.Configuration, builder.Environment.IsDevelopment())
.WithUserCheck(async (email, sp) =>
{
var db = sp.GetRequiredService<MyDbContext>();
var user = await db.Users.FirstOrDefaultAsync(u => u.Email == email);
return user == null ? null : new PrimusAuthUser { Id = user.Id, Email = user.Email, Role = user.Role };
})
.WithAutoProvision(async (email, provider, principal, sp) =>
{
// JIT provisioning (optional)
var db = sp.GetRequiredService<MyDbContext>();
var user = new User { Email = email, CreatedAt = DateTime.UtcNow };
db.Users.Add(user);
await db.SaveChangesAsync();
return new PrimusAuthUser { Id = user.Id, Email = user.Email };
});
Local login is handled by the broker at POST /api/auth/login. To enable it, implement
IPrimusAuthCredentialValidator and verify credentials against your data store.
public class MyCredentialValidator : IPrimusAuthCredentialValidator
{
private readonly MyDbContext _db;
private readonly IPasswordHasher _hasher;
public MyCredentialValidator(MyDbContext db, IPasswordHasher hasher)
{
_db = db;
_hasher = hasher;
}
public async Task<PrimusAuthUser?> ValidateCredentialsAsync(string email, string password, CancellationToken ct = default)
{
var user = await _db.Users.FirstOrDefaultAsync(u => u.Email == email, ct);
if (user == null || !_hasher.VerifyPassword(password, user.PasswordHash))
{
return null;
}
return new PrimusAuthUser { Id = user.Id, Email = user.Email, Role = user.Role };
}
}
builder.Services.AddScoped<IPrimusAuthCredentialValidator, MyCredentialValidator>(); // If using local login
builder.Services.AddPrimusAuthBroker(builder.Configuration, builder.Environment.IsDevelopment());
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.UsePrimusCsrfProtection();
app.MapPrimusAuthBroker();
If token encryption remains enabled, configure PrimusAuth:Security:TokenEncryptionKey before startup. For a local-only sample host, you can instead use:
builder.Services.AddPrimusAuthBroker(
builder.Configuration,
builder.Environment.IsDevelopment(),
options => options.Security.EncryptTokens = false);
Azure AD uses /api/auth/azure/callback by default (or {AuthBroker:BasePath}/azure/callback).
Override with AzureAd:CallbackPath if your app registration already uses /signin-oidc.
Note: POST /api/auth/login requires a CSRF token. Call a safe endpoint like
GET /api/auth/providers on app startup to receive the XSRF-TOKEN cookie,
then mirror it in the X-Primus-CSRF header for state-changing requests.
builder.Services.AddPrimusBrokerDataProtection("MyUniqueAppName", new DirectoryInfo(@"C:\Keys"));
You may see an SCS0009 warning about the XSRF-TOKEN cookie missing the HttpOnly flag. That is intentional. The browser-side code must be able to read that value and mirror it into the X-Primus-CSRF header for the double-submit-cookie pattern to work.
You can control where users are sent after login or error.
"Auth": {
"PostLoginRedirect": "/",
"ErrorRedirect": "/login"
}
User is not provisioned). If not set, a simple HTML error page is shown. The error message is passed as a query string: ?error=....The broker includes an impersonation flow for support and administrative scenarios.
How to use:
role: Admin./api/auth/impersonate with {"targetEmail": "customer@example.com"}.act: admin@me.com for audit trails./api/auth/revert (Logs you out).In Development environment only, you can view the current configuration status at:
GET /api/auth/__auth/diagnostics
This endpoint will show:
IPrimusAuthUserStore. See Step 2 above.CookieSameSiteMode. If using HTTP (not HTTPS), ensure your browser allows cookies.| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 5 NuGet packages that depend on PrimusSaaS.Identity.Broker:
| Package | Downloads |
|---|---|
|
PrimusSaaS.Identity.Broker.Tokens
Optional token issuance add-on for PrimusSaaS.Identity.Broker. Adds broker-issued access tokens, refresh tokens, and token exchange endpoints without changing the broker's default cookie-based behavior. |
|
|
PrimusSaaS.Memberships.InMemory
In-memory stores and bridge adapters for PrimusSaaS.Memberships development and test scenarios. |
|
|
PrimusSaaS.Identity.Broker.Redis
Redis-backed rate limiter and distributed audit sink for PrimusSaaS.Identity.Broker. Required for multi-instance deployments to prevent per-instance rate limit bypass. |
|
|
PrimusSaaS.Memberships.EFCore
Entity Framework Core integration for PrimusSaaS.Memberships. |
|
|
PrimusSaaS.Identity.Broker.EntityFrameworkCore
Entity Framework Core user store for PrimusSaaS.Identity.Broker. Provides a generic base class for persisting broker user state using any EF Core-compatible database. |
This package is not used by any popular GitHub repositories.
v2.5.1: Dedicated M2M app credentials — PrimusM2MOptions gains ClientId/ClientSecret; token service prefers them over broker credentials with fallback. | v2.5.0: M2M support — IPrimusM2MTokenService (outbound client credentials) + AddPrimusM2MValidation (inbound JwtBearer). | v2.4.0: Domain Allowlist, Webhooks, Bot Protection. | v2.3.0: TOTP MFA + token refresh. | v2.2.0: SAML 2.0.