Skip to content

Commit ba2538d

Browse files
committed
Fix OIDC callback to properly append newUser query parameter
Tool: gitpod/catfood.gitpod.cloud
1 parent 004e07a commit ba2538d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

components/public-api-server/pkg/oidc/router.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,15 @@ func (s *Service) getCallbackHandler() http.HandlerFunc {
177177
return
178178
}
179179
if message.NewUser {
180-
oauth2Result.ReturnToURL += "&newUser=true"
180+
returnURL, err := url.Parse(oauth2Result.ReturnToURL)
181+
if err != nil {
182+
log.WithError(err).Warn("Failed to parse return URL")
183+
} else {
184+
q := returnURL.Query()
185+
q.Set("newUser", "true")
186+
returnURL.RawQuery = q.Encode()
187+
oauth2Result.ReturnToURL = returnURL.String()
188+
}
181189
}
182190
for _, cookie := range cookies {
183191
http.SetCookie(rw, cookie)

components/public-api-server/pkg/oidc/router_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func TestRoute_callback(t *testing.T) {
101101

102102
url, err := resp.Location()
103103
require.NoError(t, err)
104-
require.Equal(t, "/relative/url/to/some/page", url.Path, "callback redirects properly")
104+
require.Equal(t, "/relative/url/to/some/page?newUser=true", url.Path, "callback redirects properly")
105105

106106
}
107107

0 commit comments

Comments
 (0)