Google sign-in
Set up Google sign-in end to end — provider console, backend config, frontend wiring.
The oauth/google adapter implements Signet's public OAuthProvider interface. It uses PKCE,
requests openid email profile, and reads the verified identity from Google's userinfo endpoint.
1. Create the Google OAuth client
- In the Google Cloud Console, create or select a project.
- APIs & Services → OAuth consent screen: choose External, fill in the app name and a
support email. No sensitive scopes are needed — the basic profile data comes through the
standard
openid email profilescopes Signet requests. - APIs & Services → Credentials → Create credentials → OAuth client ID, application type Web application.
- Under Authorized redirect URIs, add
https://api.example.com/auth/oauth/callback(adjust for yourPathPrefix). Google requires an HTTPS URL. - Copy the Client ID and Client secret into
GOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRETon the backend.
2. Configure the backend
import (
"encoding/base64"
"os"
"github.com/shakibdshy/signet-auth"
"github.com/shakibdshy/signet-auth/oauth/google"
)
stateKey, err := base64.StdEncoding.DecodeString(os.Getenv("SIGNET_OAUTH_STATE_KEY"))
cfg.OAuth = &signet.OAuthConfig{
Providers: []signet.OAuthProvider{
google.Provider{
ClientID: os.Getenv("GOOGLE_CLIENT_ID"),
ClientSecret: os.Getenv("GOOGLE_CLIENT_SECRET"),
},
},
RedirectBaseURL: "https://app.example.com",
AllowedRedirects: []string{"https://app.example.com/auth/callback"},
StateKey: stateKey, // exactly 32 bytes
}RedirectBaseURL is the origin Google is redirected back to; Signet builds the callback URL
from it and your PathPrefix. AllowedRedirects is an exact-match allowlist (optionally
extended with validated redirect patterns) of where users may land afterwards.
Generate the state key once with openssl rand -base64 32 and keep it stable: it is the
AES-GCM key for the sealed OAuth state, so rotating it breaks every in-flight sign-in, and
every replica serving the callback must share the same value.
The example above keeps the app and the API on one origin — Signet issues SameSite=Lax
cookies and no CORS headers, so a split browser/backend deployment needs a reverse proxy on a
single origin. See Security.
3. The browser flow
- The frontend asks the backend to start sign-in:
POST /auth/oauth/startwith{"provider": "google", "redirect": "https://app.example.com/auth/callback"}. The endpoint is anonymous and returns{"url": "..."}— the Google authorization URL with PKCE and a sealed, single-use state (AES-GCM underStateKey, 10-minute expiry). - Redirect the browser to that
url. Google authenticates the User and calls the registered callback. Signet owns that endpoint — you never implement it. - On success Signet sets the Session cookie and redirects (302) to your
redirectURL. The landing page then reads the session like any other sign-in —useSession()in a React app,GET /auth/sessionotherwise. - On failure — expired state, provider error, account conflict — the callback answers with a
JSON error body (
{"error": ..., "message": ...}) instead of a redirect, so a stale start URL simply shows that error; have the User start over.
4. Linking when the email is unverified
Signet auto-links a provider identity only when the email is verified. If Google reports the
address unverified, the callback still redirects to your redirect URL but appends
?link_token=... instead of setting a Session. Your backend consumes it with the Go API —
client.LinkOAuthAccount(ctx, signet.LinkOAuthAccountInput{UserID: ..., LinkToken: ...}),
which links the provider Account to that User after explicit consent — and the User signs in
again through Google, now auto-linked.
Identity details
- Provider name stored on the Account:
google(also the value the frontend passes tooauthStart). - Provider user ID: Google's stable
subclaim. - Email and verification flag come from
https://www.googleapis.com/oauth2/v3/userinfo. - A provider Account owned by another User is rejected with an account-conflict error.
Endpoints
AuthEndpoint, TokenURL and UserInfoURL fields override the defaults. They exist for tests;
leave them empty in production so Google's real endpoints are used.
See OAuth sign-in for the shared flow, state encryption and redirect rules.