Skip to content

Commit f5fac44

Browse files
move OAuth route to project group (#473)
Signed-off-by: Michael Clifford <mcliffor@redhat.com>
1 parent f4b7328 commit f5fac44

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

components/backend/handlers/oauth.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,35 @@ func GetOAuthURL(c *gin.Context) {
105105
providerName = "google"
106106
}
107107

108+
// Verify user has access to the session using user token
109+
reqK8s, reqDyn := GetK8sClientsForRequest(c)
110+
if reqK8s == nil {
111+
c.JSON(http.StatusUnauthorized, gin.H{"error": "Invalid or missing token"})
112+
return
113+
}
114+
115+
// Verify session exists and user has access
116+
gvr := schema.GroupVersionResource{
117+
Group: "vteam.ambient-code",
118+
Version: "v1alpha1",
119+
Resource: "agenticsessions",
120+
}
121+
122+
_, err := reqDyn.Resource(gvr).Namespace(projectName).Get(context.Background(), sessionName, v1.GetOptions{})
123+
if errors.IsNotFound(err) {
124+
c.JSON(http.StatusNotFound, gin.H{"error": "Session not found"})
125+
return
126+
}
127+
if errors.IsForbidden(err) {
128+
c.JSON(http.StatusForbidden, gin.H{"error": "Access denied to session"})
129+
return
130+
}
131+
if err != nil {
132+
log.Printf("Failed to get session %s/%s: %v", projectName, sessionName, err)
133+
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to verify session"})
134+
return
135+
}
136+
108137
// Get OAuth provider config
109138
provider, err := getOAuthProvider(providerName)
110139
if err != nil {

components/backend/routes.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ func registerRoutes(r *gin.Engine) {
3535

3636
api.POST("/projects/:projectName/agentic-sessions/:sessionName/github/token", handlers.MintSessionGitHubToken)
3737

38-
// OAuth integration endpoints (no auth required - called by external OAuth providers)
39-
// OAuth URL generation endpoint - returns signed OAuth URL with HMAC-protected state
40-
api.GET("/projects/:projectName/agentic-sessions/:sessionName/oauth/:provider/url", handlers.GetOAuthURL)
41-
4238
projectGroup := api.Group("/projects/:projectName", handlers.ValidateProjectContext())
4339
{
4440
projectGroup.GET("/access", handlers.AccessCheck)
@@ -84,6 +80,9 @@ func registerRoutes(r *gin.Engine) {
8480
projectGroup.DELETE("/agentic-sessions/:sessionName/repos/:repoName", handlers.RemoveRepo)
8581
projectGroup.PUT("/agentic-sessions/:sessionName/displayname", handlers.UpdateSessionDisplayName)
8682

83+
// OAuth integration - requires user auth like all other session endpoints
84+
projectGroup.GET("/agentic-sessions/:sessionName/oauth/:provider/url", handlers.GetOAuthURL)
85+
8786
projectGroup.GET("/sessions/:sessionId/ws", websocket.HandleSessionWebSocket)
8887
projectGroup.GET("/sessions/:sessionId/messages", websocket.GetSessionMessagesWS)
8988
// Removed: /messages/claude-format - Using SDK's built-in resume with persisted ~/.claude state

0 commit comments

Comments
 (0)