google-auth
Skill1 starsChanged 4 months agoMITView on GitHub
Google Sign-In / OAuth 2.0 / OIDC-specific expertise — choosing the right flow (server-side authorization code + PKCE, or Google Identity Services for sign-in only; never implicit, no client secret in a public client), the ID token vs access token distinction and full server-side verification (signature via Google's JWKS, `iss`, `aud`, `exp`, `email_verified`, and `sub` as the stable user key), `state`/nonce for CSRF and replay, exact redirect-URI matching and safe post-login redirects, minimal and incremental scopes, refresh tokens (`access_type=offline`, encrypted at rest, revocation handling), session cookies minted by your own app rather than storing Google tokens in the browser, and the account-linking hazards around unverified email. Use when `package.json` lists `google-auth-library`, `@react-oauth/google`, `passport-google-oauth20`, or an auth framework's Google provider (NextAuth/Auth.js, Lucia, Supabase, Firebase), when `GOOGLE_CLIENT_ID`/`GOOGLE_CLIENT_SECRET` appear in env files, or when asked directly (Thai or English) to ทำ Login with Google / เข้าสู่ระบบด้วย Google หรือแก้ปัญหา OAuth. Not a replacement for api-integration-dev's SDK wiring or security-auditor's audit — this is the protocol-level expertise both draw on.
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- anthroos/claude-skills-opentheir own version, first seen Mar 5, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- anthroos/claude-skills-open★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- agent-flowSkill
- dev-testingSkill
- dry-and-corSkill
- electronSkill
- firebaseSkill
- flutterSkill
- html-cssSkill
- mysqlSkill
- nodejsSkill
- postgresSkill
- reactSkill
- sqliteSkill
- stack-briefingSkill
- supabaseSkill
- tailwindSkill
- tursoSkill
- typescriptSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
16 rules. About 0 are common, 6 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
Check package.json for google-auth-library, googleapis, @react-oauth/google, passport-google-oauth20, or an auth framework's Google …
- Very specific: line 65
Use Google's library (google-auth-library's verifyIdToken, or an equivalent OIDC library with Google's JWKS) — never jwt.decode without …
- Very specific: line 82
Use sub as the stable user identifier in your database.
- Very specific: line 84
If it's a Workspace-only app, check the hd (hosted domain) claim server-side — filtering with the hd request parameter alone is a hint to …
- Very specific: line 96
Don't store ID tokens, access tokens, or refresh tokens in localStorage/sessionStorage, where any XSS reads them.
- Distinctive: line 123
Ask for additional scopes incrementally, at the moment the feature needs them, not all at first login.
- Distinctive: line 171
Don't use the implicit flow, and don't put a client secret in an SPA, mobile app, or Electron bundle.
- Very specific: line 173
Don't decode an ID token without verifying its signature, and never skip the aud check.
- Very specific: line 175
Don't trust email before email_verified, and don't key users by email.
- Distinctive: line 176
Don't use a Google access token as your app's session or as proof of identity.
- Very specific: line 178
Don't store Google tokens in localStorage, and don't log them.
- Very specific: line 179
Don't skip state/nonce, and don't redirect after login to a URL taken from a query parameter.
- Very specific: line 181
Don't assume a refresh token arrives on every login, and don't retry blindly on invalid_grant.
- Distinctive: line 183
Don't request scopes the feature doesn't use yet.
- Distinctive: line 184
Don't auto-link a Google identity to an existing account on an unverified email match.
- Distinctive: line 186
Don't hand-roll a second session mechanism next to the auth framework the project already uses.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Google Auth (OAuth 2.0 / OpenID Connect)
The protocol layer under "Sign in with Google". api-integration-dev wires
the SDK and backend-dev owns the session and the user record; this skill
is what makes the result actually authenticate someone. Most Google-sign-in
bugs are not SDK bugs — they are a token used for the wrong purpose, a check
that was skipped, or a redirect that wasn't pinned.
Step 1 — Confirm the task and read what's already wired
Check package.json for google-auth-library, googleapis,
@react-oauth/google, passport-google-oauth20, or an auth framework's
Google provider; GOOGLE_CLIENT_ID/GOOGLE_CLIENT_SECRET in
.env.example; or an existing /auth/google/callback route. If a framework
already owns the flow (Auth.js, Lucia, Supabase Auth, Firebase Auth),
configure it correctly rather than hand-rolling a parallel flow — two
session mechanisms in one app is its own vulnerability. This skill then
applies to the parts the framework leaves to you: scopes, verification of
anything you decode yourself, session cookie settings, and redirect
handling.
Step 2 — Pick the right flow
- Authorization Code + PKCE, exchanged on your server — the default for
a web app that needs a session, and mandatory if you need any Google API
access beyond identity. The
codeis exchanged server-side using the client secret; the browser never sees a Google token. - Google Identity Services (One Tap / Sign in with Google button) — correct when all you need is identity. It returns an ID token (a JWT) that your server verifies. No client secret involved, no access token, no Google API access.
- Implicit flow (
response_type=token) is deprecated and must not be used — tokens land in the URL fragment, in history and logs. - Public clients (SPA, mobile, desktop, Electron) have no client secret. A secret shipped in a bundle is public; if one is there, treat it as compromised and rotate it. Use PKCE, and on desktop use a loopback redirect or the system browser rather than an embedded webview (Google blocks embedded webviews for sign-in, and they defeat the user's ability to see the real origin).
- Register exact redirect URIs per environment (dev, staging, prod). Google matches them exactly — no wildcards, no path prefixes, scheme and port included.
Step 3 — ID token vs access token
These are not interchangeable, and confusing them is the most common design error:
- ID token (
id_token, a JWT) answers who the user is. It is for your application, and it is what you verify to establish identity. - Access token answers what Google APIs the bearer may call. It is opaque to you, is meant for Google's servers, and must never be used as proof of identity or as a session credential in your app.
- Neither one is your session. After verifying identity once, mint your own session (see Step 5); don't ask the browser to hold Google tokens and re-present them.
Step 4 — Verify the ID token properly, server-side
Use Google's library (google-auth-library's verifyIdToken, or an
equivalent OIDC library with Google's JWKS) — never jwt.decode without
verification, and never trust a token the client says is valid. The checks
that must all pass:
- Signature against Google's published JWKS, with a supported algorithm
(
RS256) — rejectalg: noneand reject an algorithm the code didn't expect. audequals your client ID. Skipping this accepts a valid Google token minted for a different application — a complete authentication bypass.issishttps://accounts.google.comoraccounts.google.com.exp(andiat) still valid, with only small clock skew allowed.noncematches the one you generated for this login, when the flow supplies one — that's the replay defense.email_verifiedis true before trustingemailfor anything, especially account linking.- Use
subas the stable user identifier in your database. Email addresses change and can be reassigned;subdoes not. - If it's a Workspace-only app, check the
hd(hosted domain) claim server-side — filtering with thehdrequest parameter alone is a hint to the login UI, not enforcement.
Step 5 — Sessions after login
- Mint your own session on success: an opaque session ID (or your own signed
JWT) in a cookie that is
HttpOnly,Secure,SameSite=Lax(orStrictwhere the flow allows),Path=/, with a sane expiry. - Regenerate the session identifier at login to prevent session fixation, and invalidate server-side on logout — deleting a cookie isn't a logout if the session is still valid.
- Don't store ID tokens, access tokens, or refresh tokens in
localStorage/sessionStorage, where any XSS reads them. - Provide real logout: clear your session, and revoke the Google refresh token if you hold one.
Step 6 — state, redirects, and callback safety
- Send a cryptographically random, single-use
stateand verify it on the callback — that is the CSRF defense for the authorization code flow. Bind it to the browser (a short-lived cookie), don't just keep a global set. - Store the PKCE
code_verifierper-attempt server-side (or in a secure cookie) and use it exactly once. - A post-login "return to" destination must be validated against an allowlist of internal paths, or you have built an open redirect that phishing will use. Never redirect to an absolute URL supplied in a query parameter.
- Handle the user-denies and error responses (
error=access_denied) explicitly instead of leaving a blank screen or an unhandled exception. - The callback route is unauthenticated and internet-reachable: rate-limit it and don't leak token contents in logs or error pages.
Step 7 — Scopes, refresh tokens, and API access
- Request the minimum:
openid email profilecovers sign-in. Every extra scope is more consent friction, a bigger blast radius, and — for sensitive or restricted scopes (Gmail, Drive, Calendar contents) — a Google verification review with a security assessment. - Ask for additional scopes incrementally, at the moment the feature needs them, not all at first login.
- A refresh token is only issued with
access_type=offline, and typically only on the first consent — soprompt=consentis needed to get a new one after the first. Code that assumes a refresh token on every login silently breaks on the second sign-in. - Refresh tokens are long-lived credentials: encrypt them at rest, never log
them, and scope database access to them tightly. Handle
invalid_grant(user revoked access, password change, token expiry after inactivity, or a project still in testing status) by clearing the stored token and re-prompting — not by retrying. - Access tokens expire in about an hour; refresh on demand and cache server-side, don't request one per API call.
- Client secret, client ID, and redirect URIs are environment config —
devops-devwires them; never commit values.
Step 8 — Account linking and identity edge cases
- Linking a Google login to an existing local account by email alone is an
account takeover path unless
email_verifiedis true and the local account's email is verified too. Require an explicit link step from a logged-in session when either side is unverified. - One person can hold several Google accounts, and a Workspace address can
be deleted and reissued to a different human — key on
sub, and treat an email change as a profile update, not a new identity. - Users can revoke your app's access at any time from their Google account; the next API call fails, and the app must degrade to a re-consent prompt.
- Deleting a user in your app should revoke the stored Google token too.
Step 9 — Self-check before reporting done
Confirm the flow is authorization code + PKCE (or GIS ID token) with no
client secret in anything shipped to a browser or device. Confirm the ID
token is verified server-side with signature, aud, iss, exp, and
nonce, that email_verified gates any use of email, and that sub is the
stored key. Confirm state is generated, single-use, and checked; that
redirect URIs are exact per environment and any post-login destination is
allowlisted. Confirm the app mints its own HttpOnly/Secure session
cookie, regenerated at login, and that no Google token is in browser
storage. Confirm scopes are minimal and any refresh token is encrypted with
invalid_grant handled. Then run the real flow end to end
(skills/dev-testing/SKILL.md) — a fresh user, an existing user, a denied
consent, and a second login — and check the session and user row that
result, not just the redirect. Route anything touching the trust boundary
past security-auditor.
What not to do
- Don't use the implicit flow, and don't put a client secret in an SPA, mobile app, or Electron bundle.
- Don't decode an ID token without verifying its signature, and never skip
the
audcheck. - Don't trust
emailbeforeemail_verified, and don't key users by email. - Don't use a Google access token as your app's session or as proof of identity.
- Don't store Google tokens in
localStorage, and don't log them. - Don't skip
state/nonce, and don't redirect after login to a URL taken from a query parameter. - Don't assume a refresh token arrives on every login, and don't retry
blindly on
invalid_grant. - Don't request scopes the feature doesn't use yet.
- Don't auto-link a Google identity to an existing account on an unverified email match.
- Don't hand-roll a second session mechanism next to the auth framework the project already uses.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

