wowprompt

Sign in with Google using OpenID Connect with state and nonce checks

Writes server-side "Sign in with Google" for a web app using the authorization code flow, with state and nonce checks, ID token verification, account linking by verified email and a safe session afterwards. Use it when adding Google login to an existing site with its own user table, in PHP, Node, Python or another backend.

Server code for the login redirect and callback, ID token checks listed one by one, account linking rules, session setup and a security checklist
The output this prompt produced, unedited.

The prompt

What to give

  • Backend language and framework: [e.g. PHP 8.3 with no framework, or Node with Express]
  • Existing user table: [paste columns]
  • Current login method: [e.g. email and password, or none]
  • Session method: [e.g. server sessions with a cookie]
  • Callback URL: [e.g. https://example.com/auth/google/callback]
  • Where secrets are read from: [e.g. environment variables]

The code must pass every check

  1. The login route creates a random state and nonce, stores them in the session, and redirects with scope "openid email profile".
  2. The callback rejects the request if state is missing or does not match, then deletes it.
  3. The code is exchanged for tokens on the server; the client secret never reaches the browser.
  4. The ID token signature is verified against Google's published keys, and iss, aud, exp and nonce are checked.
  5. The account is matched on the stable subject ID first; email is used to link only when email_verified is true.
  6. An existing password account is linked only after the user confirms, so nobody takes over an account by email alone.
  7. The session ID is regenerated after login; cookies are Secure, HttpOnly and SameSite=Lax.
  8. Errors show a plain message and are logged without tokens.

Output format

  1. The login route and the callback route, complete, with comments.
  2. The database change for storing the Google subject ID.
  3. The account matching and linking logic as a short decision list, then in code.
  4. A test list: wrong state, expired token, unverified email, existing account, new account.

Guardrails

  • Use a well-maintained library for token verification where one exists, and name it.
  • Read the client ID and secret only from the configured source.
sign in with googlegoogle oauth loginopenid connectid token verificationsocial loginauthorization code flow

How to run this

Copy the prompt and paste it into Gemini, then set the aspect ratio to 3:4. No reference photo is needed for this one.

The prompt is written in Markdown with each part under its own heading, which is what the copy action hands over. Change one section at a time, keeping the rest intact, so you can tell which change did the work.

Related prompts

All productivity