Skip to content

refactor: move OAuth2 provider code to dedicated package #18746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

ThomasK33
Copy link
Member

Refactor OAuth2 Provider Code into Dedicated Package

This PR refactors the OAuth2 provider functionality by moving it from the main coderd package into a dedicated oauth2provider package. The change improves code organization and maintainability without changing functionality.

Key changes:

  • Created a new oauth2provider package to house all OAuth2 provider-related code
  • Moved existing OAuth2 provider functionality from coderd/identityprovider to the new package
  • Refactored handler functions to follow a consistent pattern of returning http.HandlerFunc instead of being handlers directly
  • Split large files into smaller, more focused files organized by functionality:
    • app_secrets.go - Manages OAuth2 application secrets
    • apps.go - Handles OAuth2 application CRUD operations
    • authorize.go - Implements the authorization flow
    • metadata.go - Provides OAuth2 metadata endpoints
    • registration.go - Handles dynamic client registration
    • revoke.go - Implements token revocation
    • secrets.go - Manages secret generation and validation
    • tokens.go - Handles token issuance and validation

This refactoring improves code organization and makes the OAuth2 provider functionality more maintainable while preserving all existing behavior.

@ThomasK33 ThomasK33 marked this pull request as ready for review July 3, 2025 15:01
@ThomasK33 ThomasK33 force-pushed the thomask33/07-03-refactor_oauth2_restructure_oauth2_provider_into_modular_package branch from 74ada5e to 94f8522 Compare July 3, 2025 15:16
@ThomasK33 ThomasK33 force-pushed the thomask33/07-02-feat_mcp_add_experiment_control_for_mcp_server_http_endpoints branch from 665993d to 5d752e3 Compare July 3, 2025 16:36
@ThomasK33 ThomasK33 force-pushed the thomask33/07-03-refactor_oauth2_restructure_oauth2_provider_into_modular_package branch from 94f8522 to c160ba6 Compare July 3, 2025 16:37
@ThomasK33 ThomasK33 force-pushed the thomask33/07-02-feat_mcp_add_experiment_control_for_mcp_server_http_endpoints branch from 5d752e3 to e8b598e Compare July 3, 2025 16:53
@ThomasK33 ThomasK33 force-pushed the thomask33/07-03-refactor_oauth2_restructure_oauth2_provider_into_modular_package branch from c160ba6 to 912fd87 Compare July 3, 2025 16:53
@ThomasK33 ThomasK33 force-pushed the thomask33/07-02-feat_mcp_add_experiment_control_for_mcp_server_http_endpoints branch from e8b598e to d7cac75 Compare July 3, 2025 17:14
@ThomasK33 ThomasK33 force-pushed the thomask33/07-03-refactor_oauth2_restructure_oauth2_provider_into_modular_package branch from 912fd87 to a2737b7 Compare July 3, 2025 17:15
@ThomasK33 ThomasK33 force-pushed the thomask33/07-02-feat_mcp_add_experiment_control_for_mcp_server_http_endpoints branch from d7cac75 to cb75f3a Compare July 3, 2025 17:28
@ThomasK33 ThomasK33 force-pushed the thomask33/07-03-refactor_oauth2_restructure_oauth2_provider_into_modular_package branch from a2737b7 to 865dc56 Compare July 3, 2025 17:29
@ThomasK33 ThomasK33 force-pushed the thomask33/07-02-feat_mcp_add_experiment_control_for_mcp_server_http_endpoints branch 2 times, most recently from f62413e to 9965337 Compare July 3, 2025 17:45
@ThomasK33 ThomasK33 force-pushed the thomask33/07-03-refactor_oauth2_restructure_oauth2_provider_into_modular_package branch from 865dc56 to 1f89b53 Compare July 3, 2025 17:45
@ThomasK33 ThomasK33 changed the base branch from thomask33/07-02-feat_mcp_add_experiment_control_for_mcp_server_http_endpoints to graphite-base/18746 July 3, 2025 18:09
@ThomasK33 ThomasK33 force-pushed the thomask33/07-03-refactor_oauth2_restructure_oauth2_provider_into_modular_package branch from 1f89b53 to db0f2a0 Compare July 3, 2025 18:09
@ThomasK33 ThomasK33 force-pushed the graphite-base/18746 branch from 9965337 to 7fbb3ce Compare July 3, 2025 18:09
@ThomasK33 ThomasK33 changed the base branch from graphite-base/18746 to main July 3, 2025 18:09
- Rename identityprovider package to oauth2provider for clarity
- Extract OAuth2 business logic from coderd/oauth2.go into focused modules:
  - apps.go: OAuth2 app management (CRUD operations)
  - app_secrets.go: OAuth2 app secrets management
  - metadata.go: OAuth2 server and resource metadata endpoints
  - registration.go: RFC 7591/7592 dynamic client registration
- Update route handlers to delegate to oauth2provider functions
- Preserve all existing API endpoints and Swagger documentation
- Fix compilation issues and update middleware references
- All tests passing with zero regressions

This refactoring improves code organization and maintainability while
preserving complete API compatibility.

Change-Id: Ieef7cf3683ec93667f09a0d4894190a1e1a0b16e
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33 ThomasK33 force-pushed the thomask33/07-03-refactor_oauth2_restructure_oauth2_provider_into_modular_package branch from db0f2a0 to a586976 Compare July 3, 2025 18:10
@ThomasK33 ThomasK33 merged commit c650133 into main Jul 3, 2025
35 checks passed
Copy link
Member Author

Merge activity

@ThomasK33 ThomasK33 deleted the thomask33/07-03-refactor_oauth2_restructure_oauth2_provider_into_modular_package branch July 3, 2025 18:24
@github-actions github-actions bot locked and limited conversation to collaborators Jul 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants