fix(examples): correct and harden example apps from review#31
Merged
Conversation
- Validate the discovery issuer matches the configured URL before sending the client secret - Let the test issuer mint the uid claim so the profile and admin endpoints can expose it - Keep printing token and introspection details when the UserInfo lookup fails - Add a header read timeout and header size limit to the web service server - Use the discovered userinfo endpoint instead of a hardcoded path - Return 500 instead of 401 when token info is missing from the request context - Decode JWT segments with jq instead of a hand-rolled base64url helper - Return an empty string when masking an empty token - Align cleared cookie attributes with the ones used when setting them - Ignore the go-oidc and go-jwks-multi build artifacts Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens and corrects several standalone AuthGate example apps, mainly around auth-flow correctness, safer defaults, and clearer example behavior without changing valid happy-path behavior.
Changes:
- Adds HTTP/server and OIDC cookie hardening, plus more accurate middleware error handling.
- Uses discovered endpoints and validates discovery issuer metadata before sending secrets.
- Improves JWT/demo claim coverage and CLI output behavior.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
.gitignore |
Ignores additional Go example build artifacts. |
go-cli/main.go |
Keeps printing token details when UserInfo fails and avoids masking empty tokens. |
go-jwks/get-token.sh |
Validates discovery issuer and simplifies JWT decoding through jq. |
go-jwks-multi/testissuer/main.go |
Adds support for minting the uid private claim. |
go-m2m/main.go |
Uses the discovered userinfo endpoint instead of constructing a hardcoded path. |
go-oidc/main.go |
Clears OIDC flow cookies with matching cookie attributes. |
go-webservice/main.go |
Adds header timeout/size limits and reports missing middleware context as a server error. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Build the short-lived auth cookies and their deletions through one authCookie helper so Path, Secure, and SameSite cannot drift apart - Name the 10-minute cookie lifetime as a constant Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Map the JWT base64url alphabet to standard base64 and restore padding before jq @base64d, which only accepts the standard alphabet - Without this, valid tokens whose header or payload contains - or _ failed to decode Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Describe the go-m2m userinfo call as hitting the discovered userinfo_endpoint rather than a hardcoded path - Document the new uid query parameter in the testissuer /sign table Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Drop the stale base64 prerequisite for get-token.sh --decode, which now decodes in jq - Clarify the testissuer uid param is a display-only claim, since no AccessRule gates UID Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Re-align markdown table columns in the example READMEs - Tag the m2m example output block as txt Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Applies the fixes from a maximum-effort
/code-reviewpass over the entireexamples/tree: corrects several real bugs (display, endpoint resolution, error-path output), hardens two security-sensitive flows (discovery issuer validation, HTTP header limits), makes theuidclaim demonstrable end-to-end, and tidies repo hygiene. No behavior changes for valid inputs on the happy path.AI Authorship
/code-review --fix).gitignore,go-cli/main.go,go-jwks-multi/testissuer/main.go,go-jwks/get-token.sh,go-m2m/main.go,go-oidc/main.go,go-webservice/main.goChange classification
What changed (by file)
go-jwks/get-token.sh— verify the discovery doc'sissuermatchesISSUER_URLbefore POSTingCLIENT_SECRET(matches the SDK's discovery client); rewritedecode_jwtto usejq @base64d | fromjson, dropping the hand-rolled base64url padding and the non-portablebase64 -ddependency.go-jwks-multi/testissuer/main.go— add auidquery param +<prefix>_uidclaim so theuidfield exposed by/api/profileand/api/adminis actually exercisable.go-webservice/main.go— addReadHeaderTimeout+MaxHeaderBytesto match sibling servers; return500(not401) on the middleware-misconfiguration branch, per the SDK doc.go-m2m/main.go— use the discovered userinfo endpoint instead of a hardcoded/oauth/userinfo(fixes trailing-slash double-slash and non-default paths).go-cli/main.go— keep printing token/introspection details when UserInfo fails;maskToken("")returns""instead of"****".go-oidc/main.go—clearCookienow mirrorssetShortCookie'sPath/Secure/SameSite..gitignore— ignore thego-oidcandgo-jwks-multibuild artifacts.Verification
go build ./...,go vet ./...,gofmt -lclean across all 6 modulesbash -nclean on both shell scripts; no literal control bytes lefttestissuer+ the multi-issuer resource server, minted auid=alicetoken → confirmed/api/profileand/api/adminreturnuid:"alice", and a no-uidtoken returnsuid:""get-token.shissuer-match parse (trailing slash tolerated, mismatch rejected) and thejq @base64ddecode + clean failure pathcd go-jwks-multi && go run ./testissuerthen, with the printed env,go run .; mintcurl '127.0.0.1:9001/sign?domain=oa&uid=alice'and check/api/profile.Security check (touches external interfaces)
issuernow checked before secret is sentdecode_jwtnow fails with a clean messageRisk & rollback
get-token.shnow refuses a discovery doc whoseissuerdiffers fromISSUER_URL— intended, but could surface a pre-existing misconfiguration.git revert 1d5a445(single commit).Reviewer guide
go-jwks/get-token.sh— issuer-match check and the jq-based JWT decode rewritego-oidc/main.go— cookie clearing across the OIDC callback flowgo-jwks-multi/testissuer/main.go— JWT claim mintinggo-cli/main.go,go-m2m/main.go,go-webservice/main.go,.gitignore🤖 Generated with Claude Code