Conversation
…magic strings - Extract shared clientToDisplay helper in utils.go, replacing duplicate appToDisplay and inline OAuthApplication-to-ClientDisplay conversions - Export ContextKeyClientIP constant from middleware, replacing raw "client_ip" string across handlers and tests - Merge duplicate error page rendering in redirectWithError into single conditional Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors handler code to centralize OAuth client-to-template conversion logic and standardize the gin context key used to store the client IP, reducing duplication and removing hard-coded strings across the auth/session fingerprint flows.
Changes:
- Added a shared
clientToDisplayhelper ininternal/handlers/utils.goand replaced duplicatedOAuthApplication→ClientDisplaymappings in admin/user client handlers. - Introduced
middleware.ContextKeyClientIPand replaced raw"client_ip"usages in middleware, handlers, and tests. - Simplified
AuthorizationHandler.redirectWithErrorby merging duplicate error-page rendering branches.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/middleware/context.go | Exports ContextKeyClientIP and uses it when storing client IP in gin context. |
| internal/middleware/auth.go | Uses ContextKeyClientIP when reading client IP for session fingerprinting. |
| internal/middleware/auth_test.go | Updates tests to set client IP using ContextKeyClientIP. |
| internal/handlers/utils.go | Adds shared clientToDisplay helper for template display mapping. |
| internal/handlers/client.go | Replaces inline client display mapping with clientToDisplay. |
| internal/handlers/user_client.go | Replaces appToDisplay and other conversions with clientToDisplay, removes duplicate helper. |
| internal/handlers/auth.go | Uses middleware.ContextKeyClientIP when generating login session fingerprint. |
| internal/handlers/oauth_handler.go | Uses middleware.ContextKeyClientIP when generating OAuth callback session fingerprint. |
| internal/handlers/authorization.go | Consolidates redirect error handling into a single conditional branch. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
clientToDisplayhelper inutils.go, replacing duplicateappToDisplayand 2 inlineOAuthApplication→ClientDisplayconversions acrossclient.goanduser_client.goContextKeyClientIPconstant frommiddleware/context.go, replacing 6 raw"client_ip"string occurrences across handlers, middleware, and testsauthorization.go:redirectWithErrorinto a single conditionalTest plan
go test ./...)make lint)go build ./...)🤖 Generated with Claude Code