Add isolated OAuth 2.0 + PKCE support for GPT Actions#38
Conversation
|
@copilot Review and refactor it so GPT access reuses the existing API surface instead of duplicating controllers. Context:
Goal: Required changes:
Implementation guidance:
Deliver a cleanup PR that removes the duplicated GPT controller layer and keeps only the OAuth integration + scope-based access on the existing API. |
|
@vitorhugo-java I've opened a new pull request, #39, to work on those changes. Once the pull request is ready, I'll request review from you. |
…#39) * Initial plan * Remove GptActionController; reuse existing API for GPT OAuth tokens - Delete GptActionController (duplicated /api/v1/gpt/** layer) - Narrow GptOAuthSecurityConfig chain to /oauth2/** only; remove oauth2ResourceServer and BearerTokenAuthentication* handlers - Extend JwtAuthenticationFilter to try GPT OAuth tokens as fallback when user JWT validation fails (avoids BearerTokenAuthenticationFilter conflict in the main chain) - Change GptOAuthTokenService to emit ROLE_GPT_CLIENT instead of ROLE_USER; preserve non-USER roles (e.g. ROLE_BETA) - Add URL-level hasAnyRole(USER, GPT_CLIENT) rules in SecurityConfig for each GPT-accessible path; keep hasRole(USER) catch-all for everything else - Add @PreAuthorize(hasRole(USER) or hasAuthority(SCOPE_...)) to AuthController#me, ApplicationController#{create,getAll,getById,updateStatus} - Update GoogleDriveController status/listBaseResumes/getBaseResumeContent/ getGeneratedResumeContent to require ROLE_BETA and (USER or scope) - Update OpenApiConfig gptOpenApi group to point to existing endpoint paths - Update GptOAuthFlowIT to call /api/v1/applications and /api/v1/auth/me - Update OpenApiDocumentationIT assertions to check existing paths * Make invalid-token return path explicit in tryUserJwt Add explicit return false with debug log when isTokenValid fails, so the method always returns at a clear decision point rather than falling through to the final return. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Qodana for JVM6 new problems were found
View the detailed Qodana reportTo be able to view the detailed Qodana report, you can either:
To get - name: 'Qodana Scan'
uses: JetBrains/qodana-action@v2025.3.2
with:
upload-result: trueContact Qodana teamContact us at qodana-support@jetbrains.com
|
This PR adds a dedicated OAuth 2.0 Authorization Code flow with PKCE for GPT Actions, without changing the existing JWT-based user auth or the separate Google Drive OAuth integration. It introduces scoped GPT access, explicit user binding, and GPT-oriented API surfaces that reuse the current per-user authorization model.
OAuth flow for GPT Actions
/oauth2/authorizeand/oauth2/tokenfor a dedicated GPT clientS256Isolated security model
/oauth2/**and/api/v1/gpt/**/api/v1/**scope,roles,user_id,aud,iss, andtoken_useclaimsSecurityUtilsand repository-level user isolation continue to workGPT-scoped API surface
/api/v1/gpt/**endpoints for profile, applications, resumes, Google Drive status, and metricsread:profile,read:applications, andwrite:applicationsBETAConfig and docs
OPENAI_GPT_CLIENT_IDOPENAI_GPT_CLIENT_SECRETOPENAI_GPT_REDIRECT_URISOPENAI_GPT_SCOPESREADME.mdapplication.yml,application-test.yml, and.env.examplePersistence and regression coverage
Example of the new GPT-side surface:
And the endpoint-level authorization remains explicit: