Consolidate registration endpoint synthesis into pkg/oauthproto
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 2.2k
- Forks
- 300
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 184
Description
Context
PR #5357 added an endpoint synthesis block in resolveDCRCredentials (pkg/auth/discovery/discovery.go:737-745) to handle the ErrRegistrationEndpointMissing case when re-fetching AS metadata. This logic duplicates synthesiseRegistrationEndpoint in pkg/auth/dcr/resolver.go:1020-1033, which is unexported and unreachable from pkg/auth/discovery.
The duplication was called out as a non-blocking nit during review of #5357. Both sites implement the same nanobot/Hydra convention: build {issuer}/register by joining the issuer's scheme, host, and trimmed path with /register.
Problem
Two identical implementations of the same URL construction rule will drift if either site is updated (e.g. scheme/host validation is added to one, or the convention changes). There is no test that the two sites produce identical output for the same input.
Proposed fix
- Move
synthesiseRegistrationEndpoint(or an equivalent) topkg/oauthproto, the natural home for AS URL construction utilities alongsideFetchAuthorizationServerMetadataandbuildDiscoveryURLs. - Update both call sites —
pkg/auth/dcr/resolver.goandpkg/auth/discovery/discovery.go— to use the shared function. - Add a test asserting both callers produce identical results for the same issuer input.
This work is a natural companion to the larger follow-up of threading code_challenge_methods_supported through AuthServerInfo (also noted in #5357), which would eliminate the re-fetch in resolveDCRCredentials entirely and with it the second call site.
References
- #5357 (introduced the duplication, fix for #5356)
pkg/auth/dcr/resolver.go:1020—synthesiseRegistrationEndpointpkg/auth/discovery/discovery.go:737— duplicate inline block
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with synthesiseRegistrationEndpoint in pkg/auth/dcr/resolver.go:1020-1033 and the duplicate block in pkg/auth/discovery/discovery.go:737-745, then inspect pkg/oauthproto alongside FetchAuthorizationServerMetadata and buildDiscoveryURLs. Move the shared URL construction there, update both callers, and add a test showing identical results for the same issuer input. Run the affected Go package tests to verify the shared behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, authentication, backend
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 70/100