Skip to content

Commit a80be32

Browse files
authored
feat(controlplane): support providing connection string (#592)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent c3ecca7 commit a80be32

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

app/controlplane/internal/service/auth.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -167,8 +167,24 @@ func loginHandler(svc *AuthService, w http.ResponseWriter, r *http.Request) (int
167167
// Wether the token should be short lived or not
168168
setOauthCookie(w, cookieLongLived, r.URL.Query().Get(oauth.QueryParamLongLived))
169169

170-
url := svc.authenticator.AuthCodeURL(state)
171-
http.Redirect(w, r, url, http.StatusFound)
170+
authorizationURI := svc.authenticator.AuthCodeURL(state)
171+
172+
// Add the connection parameter to the authorization URL if needed
173+
// ?connection is useful for example in auth0 to know which connection to use
174+
// https://auth0.com/docs/api/authentication#login
175+
connectionStr := r.URL.Query().Get(oauth.QueryParamAuth0Connection)
176+
if connectionStr != "" {
177+
uri, err := url.Parse(authorizationURI)
178+
if err != nil {
179+
return http.StatusInternalServerError, sl.LogAndMaskErr(err, svc.log)
180+
}
181+
q := uri.Query()
182+
q.Set("connection", connectionStr)
183+
uri.RawQuery = q.Encode()
184+
authorizationURI = uri.String()
185+
}
186+
187+
http.Redirect(w, r, authorizationURI, http.StatusFound)
172188
return http.StatusTemporaryRedirect, nil
173189
}
174190

internal/oauth/constants.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2023 The Chainloop Authors.
2+
// Copyright 2024 The Chainloop Authors.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package oauth
1818
const (
1919
// URL query params used in the OAuth flow
2020
// Shared in a parent module so both clients and servers can use them
21-
QueryParamCallback = "callback"
22-
QueryParamLongLived = "long-lived"
21+
QueryParamCallback = "callback"
22+
QueryParamLongLived = "long-lived"
23+
QueryParamAuth0Connection = "connection"
2324
)

0 commit comments

Comments
 (0)