Refactor shared account-link nonce creation for OIDC and OAuth2#324
Merged
Conversation
6 tasks
Copilot
AI
changed the title
[WIP] Refactor duplicated CreateLinkNonce logic in OIDCHandler and OAuth2Handler
Refactor shared account-link nonce creation for OIDC and OAuth2
May 23, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR completes deduplication of the OIDC/OAuth2 account-link nonce issuance path by centralizing nonce generation inside the shared createLinkNonce helper, so both handlers follow the same end-to-end implementation.
Changes:
- Refactored
createLinkNonce(shared helper) to generate the nonce internally and removed the generator callback parameter. - Updated
OIDCHandler.CreateLinkNonceto call the new helper signature. - Updated
OAuth2Handler.CreateLinkNonceto call the new helper signature.
Show a summary per file
| File | Description |
|---|---|
| handler/oidc.go | Updates OIDC link-nonce issuance to use the shared helper without a custom generator callback. |
| handler/oauth2.go | Updates OAuth2 link-nonce issuance to use the shared helper without an inline nonce generator. |
| handler/oauth2_common.go | Centralizes nonce generation within createLinkNonce, simplifying the shared issuance flow. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OIDC and OAuth2 account-link flows still shared nearly identical
CreateLinkNoncelogic, with only a superficial difference in how the nonce string was generated. This change finishes the deduplication by moving nonce generation into the shared helper so both handlers follow the same issuance path.What changed
createLinkNonceinhandler/oauth2_common.goso it owns nonce generation, hashing, storage, and response writing.OIDCHandler.CreateLinkNonceandOAuth2Handler.CreateLinkNonceto delegate using only the nonce store and TTL.Result
generateOIDCState()andauth.GenerateRandomBase64(32)for account-link nonces.Representative change
Greptile Summary
This PR removes the
generateNoncecallback parameter from the sharedcreateLinkNoncehelper and inlinesauth.GenerateRandomBase64(32)directly, consolidating nonce issuance for both OIDC and OAuth2 account-linking flows into one implementation. Both handlers now callcreateLinkNoncewith only a store and TTL.handler/oauth2_common.go: Drops thegenerateNonce func() (string, error)parameter and callsauth.GenerateRandomBase64(32)directly; all downstream logic (hash, persist, respond) is unchanged.handler/oidc.go/handler/oauth2.go: Call sites updated to omit the now-removed callback — sincegenerateOIDCStatewas itself just a thin wrapper aroundauth.GenerateRandomBase64(32), the behavioral difference is zero.Confidence Score: 5/5
Safe to merge — the refactoring removes indirection without changing any observable behavior.
Both the old OIDC callback (generateOIDCState) and the old OAuth2 callback were thin wrappers around the same auth.GenerateRandomBase64(32) call, so the unified implementation is byte-for-byte equivalent at runtime. Hash, storage, and response logic are untouched. The slog calls in the modified function already pass r.Context() via ErrorContext, satisfying the team's context-logging requirement.
No files require special attention.
Important Files Changed
Sequence Diagram
sequenceDiagram participant Client participant Handler as OIDC/OAuth2 Handler participant Helper as createLinkNonce participant Store as OIDCLinkNonceStore participant AuthPkg as auth package Client->>Handler: POST /link-nonce Handler->>Helper: store, ttl Helper->>AuthPkg: GenerateRandomBase64(32) AuthPkg-->>Helper: nonce string Helper->>AuthPkg: HashHighEntropyToken(nonce) AuthPkg-->>Helper: nonceHash Helper->>Store: CreateLinkNonce(ctx, userID, nonceHash, expiry) Store-->>Helper: ok Helper-->>Client: "200 JSON {nonce}"Reviews (1): Last reviewed commit: "refactor: unify link nonce generation" | Re-trigger Greptile