Add OAuth 2.0 + PKCE support for GPT Actions with unified API surface#39
Merged
vitorhugo-java merged 3 commits intoMay 29, 2026
Conversation
- 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
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.
Copilot
AI
changed the title
[WIP] Add isolated OAuth 2.0 + PKCE support for GPT Actions
Add OAuth 2.0 + PKCE support for GPT Actions with unified API surface
May 29, 2026
vitorhugo-java
pushed a commit
that referenced
this pull request
May 29, 2026
* Add GPT OAuth implementation scaffold * Add GPT action endpoints and docs * Address GPT OAuth validation feedback * Add OAuth 2.0 + PKCE support for GPT Actions with unified API surface (#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> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
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.
This PR adds an 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. GPT tokens authenticate against the existing
/api/v1/**endpoints directly — no duplicate controller layer.OAuth flow for GPT Actions
/oauth2/authorizeand/oauth2/tokenfor a dedicated GPT clientS256Unified security model
GptOAuthSecurityConfigchain scoped to/oauth2/**only; OAuth endpoints are publicJwtAuthenticationFilterextended to try GPT OAuth tokens as a fallback after user JWT validation, keeping both auth modes in the same chain withoutBearerTokenAuthenticationFilterconflictsROLE_GPT_CLIENT(notROLE_USER) plus any non-USER roles (e.g.ROLE_BETA), making scope checks meaningfulJwtAuthenticationTokensubject resolves to the user email soSecurityUtilsand repository-level user isolation continue to work unchangedOne API surface, two authentication modes
/api/v1/gpt/**duplicate layerAuthController#me,ApplicationController#{create,getAll,getById,updateStatus}annotated with@PreAuthorize("hasRole('USER') or hasAuthority('SCOPE_...')")hasRole('BETA') and (hasRole('USER') or hasAuthority('SCOPE_...')); all other Google Drive endpoints remain USER-only at URL levelhasAnyRole("USER","GPT_CLIENT")guards inSecurityConfigfor each GPT-accessible path;hasRole("USER")catch-all covers everything elseConfig and docs
OPENAI_GPT_CLIENT_IDOPENAI_GPT_CLIENT_SECRETOPENAI_GPT_REDIRECT_URISOPENAI_GPT_SCOPESgpt-actionsgroup lists the real existing endpoint paths instead of a parallel controller sectionREADME.mdapplication.yml,application-test.yml, and.env.examplePersistence and regression coverage
Example GPT flow:
Endpoint-level authorization on the existing controllers: