Pinqponq.Auth.Sso.Google 1.0.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Pinqponq.Auth.Sso.Google --version 1.0.0
                    
NuGet\Install-Package Pinqponq.Auth.Sso.Google -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pinqponq.Auth.Sso.Google" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pinqponq.Auth.Sso.Google" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Pinqponq.Auth.Sso.Google" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pinqponq.Auth.Sso.Google --version 1.0.0
                    
#r "nuget: Pinqponq.Auth.Sso.Google, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Pinqponq.Auth.Sso.Google@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pinqponq.Auth.Sso.Google&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Pinqponq.Auth.Sso.Google&version=1.0.0
                    
Install as a Cake Tool

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_token itself (e.g. Google Identity Services / Sign in with Google on the frontend); this package only validates an already-issued id_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_token from Google (e.g. Google Identity Services) and send it to your backend; this package validates that token's signature, audience, issuer, and expiry via GoogleJsonWebSignature.ValidateAsync — it does not handle authorization-code exchange.
  • ⚠️ Evaluate hd and email verification before auto-linking an account by email. ExternalUserInfo.Email/EmailVerified come straight from Google's payload. Before treating a Google sign-in as "the same user" as an existing local account with a matching email, confirm EmailVerified is true (enforced by RequireEmailVerified, on by default) and, if you restrict sign-in to a Workspace domain, that hd matches your expected domain (HostedDomain). A personal @gmail.com address 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 treating Email as a hint for account discovery at most.
  • Nonce checking is opt-in. When RequireNonce is true, a request without a Nonce fails immediately; when a Nonce is supplied, it is compared to the token's nonce claim 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.

Samples

Try this package in the browser via Pinqponq.Playground — see samples/README.md.

Repository

https://github.com/pinqponq/pinqnuqets

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 138 10/6/2026
1.0.1 143 8/7/2026
1.0.0 123 8/7/2026