Skip to main content

Google

Configure Google OAuth for workforce or customer authentication.

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

{
"Google": {
"ClientId": "YOUR_CLIENT_ID",
"ClientSecret": "YOUR_CLIENT_SECRET"
}
}
How to get configuration values
  1. Go to Google Cloud Console > APIs & Services > Credentials.
  2. Create OAuth 2.0 Client ID (Web application).
  3. Authorized redirect URI: https://your-api.com/api/auth/google/callback
  4. Copy Client ID and Client Secret.

Step 4: Configure endpoint

Broker endpoints are mapped by app.MapPrimusAuthBroker().

  • GET /api/auth/providers
  • GET /api/auth/google
  • GET /api/auth/me

Step 5: Test the endpoint

  1. Call GET /api/auth/providers once on app startup to seed the CSRF cookie.
  2. Navigate to GET /api/auth/google and sign in.
  3. Call GET /api/auth/me to confirm the session.