Pinqponq.Auth.Sso.Google
1.0.2
Prefix Reserved
dotnet add package Pinqponq.Auth.Sso.Google --version 1.0.2
NuGet\Install-Package Pinqponq.Auth.Sso.Google -Version 1.0.2
<PackageReference Include="Pinqponq.Auth.Sso.Google" Version="1.0.2" />
<PackageVersion Include="Pinqponq.Auth.Sso.Google" Version="1.0.2" />
<PackageReference Include="Pinqponq.Auth.Sso.Google" />
paket add Pinqponq.Auth.Sso.Google --version 1.0.2
#r "nuget: Pinqponq.Auth.Sso.Google, 1.0.2"
#:package Pinqponq.Auth.Sso.Google@1.0.2
#addin nuget:?package=Pinqponq.Auth.Sso.Google&version=1.0.2
#tool nuget:?package=Pinqponq.Auth.Sso.Google&version=1.0.2
Pinqponq.Auth.Sso.Google
Sign-in implementation via Google OAuth2/OIDC id_token validation. Implements
the shared IExternalAuthProvider
contract using Google.Apis.Auth
(GoogleJsonWebSignature), so no manual JWKS fetching or signature checking
is required.
Install
dotnet add package Pinqponq.Auth.Sso.Google
Requirements
- .NET 8.0, 9.0, or 10.0
- A Google OAuth 2.0 client ID (from the Google Cloud Console) — the audience
the client-side sign-in flow issues
id_tokens for - The client obtains the
id_tokenitself (e.g. Google Identity Services / Sign in with Google on the frontend); this package only validates an already-issuedid_token— it does not perform the browser/redirect flow or exchange an authorization code
Quick start
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Pinqponq.Auth.Sso.Abstractions;
using Pinqponq.Auth.Sso.Google.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddPinqponqGoogleSso(options =>
{
options.ClientIds.Add(builder.Configuration["Google:ClientId"]!);
options.RequireEmailVerified = true; // default
// options.HostedDomain = "example.com"; // restrict to a Google Workspace domain
// options.RequireNonce = true; // enable for browser OIDC flows that send a nonce
});
var app = builder.Build();
app.MapPost("/auth/google", async (
GoogleSignInRequest request,
IExternalAuthProvider googleProvider, // resolved by DI; ProviderName == "Google"
CancellationToken cancellationToken) =>
{
var result = await googleProvider.AuthenticateAsync(
ExternalAuthRequest.FromIdToken(request.IdToken, nonce: request.Nonce),
cancellationToken);
if (!result.Succeeded)
{
return Results.Unauthorized();
}
var user = result.User!;
// Evaluate hd/email verification before auto-linking by email — see
// "Notes / behavior" below. Look up or create a local account keyed by
// (Provider, Subject), then issue your own session/JWT, e.g. via
// Pinqponq.Identity's IJwtTokenGenerator.
var account = await MyAccountLookup.FindOrCreateAsync(
provider: user.Provider,
subject: user.Subject,
email: user.Email,
cancellationToken: cancellationToken);
return Results.Ok(new { account.Id, user.Name, user.Picture });
});
app.Run();
If you have multiple IExternalAuthProvider implementations registered
(Google plus others), resolve the specific one either by injecting
IEnumerable<IExternalAuthProvider> and filtering on ProviderName == GoogleAuthProvider.Name ("Google"), or by keeping a single
IExternalAuthProvider registration per provider and routing by an
endpoint/route segment as shown above.
Configuration
GoogleAuthOptions (configured via AddPinqponqGoogleSso, validated on
startup):
| Option | Default | Notes |
|---|---|---|
ClientIds |
empty | Required — must contain at least one non-empty entry. The accepted audience(s); the id_token must have been issued for one of these Google OAuth client IDs. |
HostedDomain |
null |
Optional Google Workspace hosted domain (hd claim) the token must match. When empty, hosted-domain validation is skipped. |
RequireEmailVerified |
true |
When true, authentication fails unless Google's payload reports email_verified. |
RequireNonce |
false |
When true, the request's Nonce must be present and match the id_token's nonce claim (replay binding). Defaults to false because native/mobile id_token flows may not use a nonce; enable it for browser-based OIDC flows. |
Main types
| Type | Description |
|---|---|
GoogleAuthProvider |
The IExternalAuthProvider implementation. ProviderName returns the constant GoogleAuthProvider.Name ("Google"). Registered as a singleton IExternalAuthProvider by AddPinqponqGoogleSso. |
GoogleAuthOptions |
Configuration bound at startup (see above). |
GoogleAuthProvider.AuthenticateAsync only supports the id-token flow:
calling it with ExternalAuthRequest.FromAuthorizationCode(...) (and no
IdToken) returns a failure result rather than performing a code exchange.
Notes / behavior
- Only the id-token flow is supported. Your frontend must obtain the
id_tokenfrom Google (e.g. Google Identity Services) and send it to your backend; this package validates that token's signature, audience, issuer, and expiry viaGoogleJsonWebSignature.ValidateAsync— it does not handle authorization-code exchange. - ⚠️ Evaluate
hdand email verification before auto-linking an account by email.ExternalUserInfo.Email/EmailVerifiedcome straight from Google's payload. Before treating a Google sign-in as "the same user" as an existing local account with a matching email, confirmEmailVerifiedistrue(enforced byRequireEmailVerified, on by default) and, if you restrict sign-in to a Workspace domain, thathdmatches your expected domain (HostedDomain). A personal@gmail.comaddress with an unverified or attacker-controlled email on another provider should never be auto-linked to an internal account purely by string-matching the email address — prefer keying local accounts by(Provider, Subject)and treatingEmailas a hint for account discovery at most. - Nonce checking is opt-in. When
RequireNonceistrue, a request without aNoncefails immediately; when aNonceis supplied, it is compared to the token'snonceclaim using a fixed-time comparison. - Validation failures are intentionally generic. Invalid/expired/
malformed tokens, audience mismatches, and nonce/email-verification
failures all surface as
ExternalAuthResult.Failure("Invalid Google id_token.")rather than leaking which specific check failed, to avoid giving an attacker a token-validation oracle. - Target frameworks:
net8.0,net9.0,net10.0.
Related packages
- Pinqponq.Auth.Sso.Abstractions —
the
IExternalAuthProvidercontract this package implements. - Pinqponq.Identity — issue your own JWT/refresh tokens for the local session once Google sign-in succeeds.
Samples
Try this package in the browser via Pinqponq.Playground — see samples/README.md.
Repository
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Google.Apis.Auth (>= 1.77.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.10)
- Microsoft.Extensions.Options (>= 10.0.10)
- Pinqponq.Auth.Sso.Abstractions (>= 1.0.1)
-
net8.0
- Google.Apis.Auth (>= 1.77.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options (>= 8.0.2)
- Pinqponq.Auth.Sso.Abstractions (>= 1.0.1)
-
net9.0
- Google.Apis.Auth (>= 1.77.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.18)
- Microsoft.Extensions.Options (>= 9.0.18)
- Pinqponq.Auth.Sso.Abstractions (>= 1.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.