Integration Guide
Step 1: Installing the Package
Install the PrimusSaaS.Identity.Validator package via NuGet:
dotnet add package PrimusSaaS.Identity.Validator
Step 2: Configuring Program.cs
Register the Primus Identity services and middleware in your Program.cs:
using PrimusSaaS.Identity.Validator;
var builder = WebApplication.CreateBuilder(args);
// Add Primus Identity Validator
builder.Services.AddPrimusIdentity(opts =>
builder.Configuration.GetSection("PrimusIdentity").Bind(opts));
builder.Services.AddControllers();
builder.Services.AddAuthorization();
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
Step 3: Configuring App Settings
Configure the Google provider in your appsettings.json:
{
"PrimusIdentity": {
"RequireHttpsMetadata": true,
"ValidateLifetime": true,
"ClockSkew": "00:05:00",
"Issuers": [
{
"Name": "Google",
"Type": "Google",
"Issuer": "https://accounts.google.com/",
"Authority": "https://accounts.google.com",
"Audiences": [ "YOUR_GOOGLE_CLIENT_ID.apps.googleusercontent.com" ]
}
]
}
}
How to create Google OAuth credentials and get Client ID
1. Create a Google Cloud Project
- Go to Google Cloud Console
- Click Select a project New Project
- Enter a project name (e.g.,
My API Project) - Click Create
2. Enable OAuth APIs
- Go to APIs & Services Library
- Search for and enable:
- Google+ API (for basic profile)
- Any other APIs your app needs
3. Configure OAuth Consent Screen
- Go to APIs & Services OAuth consent screen
- Select External (or Internal for Google Workspace)
- Fill in required fields:
- App name: Your application name
- User support email: Your email
- Developer contact: Your email
- Click Save and Continue
- Add scopes if needed, then continue
- Add test users if using External type
4. Create OAuth Credentials
- Go to APIs & Services Credentials
- Click Create Credentials OAuth client ID
- Select Web application
- Enter a name (e.g.,
My API) - Add Authorized redirect URIs (for web flow):
https://localhost:5001/signin-google - Click Create
- Copy the Client ID (looks like
xxxxx.apps.googleusercontent.com)
5. Generate ID Token (for testing)
For web apps, use the OAuth 2.0 Playground:
- Go to OAuth 2.0 Playground
- Click the gear icon Check "Use your own OAuth credentials"
- Enter your Client ID and Client Secret
- Select scopes:
openid,email,profile - Click Authorize APIs and sign in
- Click Exchange authorization code for tokens
- Copy the
id_tokenfrom the response
Step 4: Configuring Endpoint
Create a protected endpoint to test the authentication.
[HttpGet("google")]
[Authorize]
public IActionResult Get()
{
return Ok(new {
validated = true,
issuer = User.FindFirst("iss")?.Value,
email = User.FindFirst("email")?.Value,
name = User.FindFirst("name")?.Value
});
}
Step 5: Testing the Endpoint
Get an ID token from Google and test the endpoint:
curl -k -X GET "https://localhost:5001/google" \
-H "Authorization: Bearer <ID_TOKEN>"
Alternative: Fluent API Configuration
You can also configure Google using the fluent API:
builder.Services.AddPrimusIdentity(opts =>
{
opts.UseGoogle(
audience: "YOUR_GOOGLE_CLIENT_ID.apps.googleusercontent.com"
);
});
Google-Specific Notes
| Feature | Support |
|---|---|
| ID Tokens | Fully supported |
| Access Tokens | Not for API auth (use ID tokens) |
| Service Accounts | Use JWT with custom issuer |
| Firebase Auth | Use Google issuer with Firebase client ID |