Auth0
Configure B2C or B2B SaaS authentication with Auth0.
Step 1: Install the package
dotnet add package PrimusSaaS.Identity.Broker
Step 2: Configure Program.cs and middleware
using PrimusSaaS.Identity.Broker;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddPrimusAuthBroker(builder.Configuration, builder.Environment.IsDevelopment());
builder.Services.AddControllers();
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.UsePrimusCsrfProtection();
app.MapControllers();
app.MapPrimusAuthBroker();
app.Run();
Step 3: Configure appsettings.json
{
"Auth0": {
"Domain": "your-tenant.us.auth0.com",
"ClientId": "YOUR_CLIENT_ID",
"ClientSecret": "YOUR_CLIENT_SECRET",
"Organization": "org_123456"
}
}
How to get configuration values
- Log in to the Auth0 Dashboard.
- Go to Applications > Applications > Create Application.
- Select Regular Web App.
- Allowed Callback URLs:
https://your-api.com/api/auth/auth0/callback - Allowed Logout URLs:
https://your-app.com/ - Copy Domain, Client ID, and Client Secret.
Step 4: Configure endpoint
Broker endpoints are mapped by app.MapPrimusAuthBroker().
GET /api/auth/providersGET /api/auth/auth0GET /api/auth/me
Step 5: Test the endpoint
- Call
GET /api/auth/providersonce on app startup to seed the CSRF cookie. - Navigate to
GET /api/auth/auth0and sign in. - Call
GET /api/auth/meto confirm the session.