feat(resource,serverresource): DPoP-Nonce and UserInfo response helpers - #520
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Two pieces of every protected endpoint were hand-written each time:
- resource.AuthorizationContext.SetDPoPNonce(h) sets the DPoP-Nonce
header when Verify issued a next nonce (RFC 9449 §8), so the client's
next call carries a fresh one. It replaces the same three-line check
in identity-check and the conformance AS's two resource handlers.
- serverresource.UserInfoClaims(ctx, authz, source) builds a UserInfo
response's claims (OIDC Core §5.3.2) for an endpoint hosted with the
server:
- it refuses a token without the openid scope with 403
insufficient_scope;
- it reads which claims were requested and approved from the token
(server.RequestedUserinfoClaimsKey), and a malformed entry is an
error rather than an empty request;
- it asks the IdentityClaimsSource for those only, and not at all
when there are none;
- it drops anything the source returns beyond them, and sets "sub"
from the token.
identity-check and the conformance AS used it, and identity-check had
been ignoring a malformed entry.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The UserInfo handler's error path now has one call, writeResourceError, which already answers a non-resource error with a 500. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
osanderson
force-pushed
the
feat/userinfo-dpop-nonce-helpers
branch
from
October 2, 2026 07:39
84d24c2 to
32b39b9
Compare
|
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
This is DevX follow-up: two pieces every protected endpoint hand-wrote.
resource.AuthorizationContext.SetDPoPNonce(h http.Header)setsDPoP-NoncewhenVerifyissued a next nonce (RFC 9449 §8), so the client's next call carries a fresh one. It replaces the sameif authz.NextDPoPNonce != ""block in identity-check and in the conformance AS's UserInfo and accounts handlers.serverresource.UserInfoClaims(ctx, authz, source)builds a UserInfo response's claims (OIDC Core §5.3.2) for an endpoint hosted with the server. It lives inserverresourcebecause it usesserver.RequestedUserinfoClaimsKeyandserver.IdentityClaimsSourcewithresource.AuthorizationContext, andserverandresourcedon't import each other.openidgets a 403insufficient_scope*resource.Error.subis always the token's subject.userinfoHandleruseUserInfoClaims. The conformance AS keeps its own 403 for a token withoutopenid. identity-check'sw.Writeof the signed JWT gets a#nosec G705: gosec now traces taint through the helper, and the response is anapplication/jwtJWS, never HTML. This matches the suppression already in conformance-federation-trust-anchor.RequestedUserinfoClaimsKey's doc and GETTING_STARTED's resource-server section point at both helpers.feat).Tests
TestUserInfoClaimsReturnsOnlyWhatWasRequested: the source returns email, name, phone and a different sub. The result is email, name and the token's sub; the source was asked for exactly[email name].TestUserInfoClaimsWithNothingRequestedIsSubjectOnly: with no entry,[]ornull, the result issubalone and the source is never called.TestUserInfoClaimsRefuses: a token withoutopenidgives 403insufficient_scope; a malformed entry is an error; a source error is wrapped (errors.Is).TestSetDPoPNonce: the header is set with a nonce and absent without one.openidcheck, or the skip-when-none, or reading a malformed entry as none, each fails a test.go test ./cmd/...passes, including the conformance AS's UserInfo tests.go test -race ./resource/... ./serverresource/... ./server/...passes.🤖 Generated with Claude Code