From 4b4b767e46bf04c37bb8e7da4e1f98f53a9d7753 Mon Sep 17 00:00:00 2001 From: Marcos Lilljedahl Date: Wed, 11 Nov 2020 23:20:10 -0300 Subject: [PATCH] Add ability to configure auth redirect url per playground --- handlers/login.go | 21 +++++++++++++-------- pwd/types/playground.go | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/handlers/login.go b/handlers/login.go index f36cc39..dda3f77 100644 --- a/handlers/login.go +++ b/handlers/login.go @@ -73,15 +73,20 @@ func Login(rw http.ResponseWriter, req *http.Request) { return } - scheme := "http" - if req.TLS != nil { - scheme = "https" + if playground.AuthRedirectURL != "" { + provider.RedirectURL = playground.AuthRedirectURL + } else { + scheme := "http" + if req.TLS != nil { + scheme = "https" + } + host := "localhost" + if req.Host != "" { + host = req.Host + } + provider.RedirectURL = fmt.Sprintf("%s://%s/oauth/providers/%s/callback", scheme, host, providerName) } - host := "localhost" - if req.Host != "" { - host = req.Host - } - provider.RedirectURL = fmt.Sprintf("%s://%s/oauth/providers/%s/callback", scheme, host, providerName) + url := provider.AuthCodeURL(loginRequest.Id, oauth2.SetAuthURLParam("nonce", uuid.NewV4().String())) http.Redirect(rw, req, url, http.StatusFound) diff --git a/pwd/types/playground.go b/pwd/types/playground.go index 6f49fdb..bb24252 100644 --- a/pwd/types/playground.go +++ b/pwd/types/playground.go @@ -88,6 +88,7 @@ type Playground struct { GoogleClientSecret string `json:"google_client_secret" bson:"google_client_secret"` DockerClientID string `json:"docker_client_id" bson:"docker_client_id"` DockerClientSecret string `json:"docker_client_secret" bson:"docker_client_secret"` + AuthRedirectURL string `json:"auth_redirect_url" bson:"auth_redirect_url"` DockerHost string `json:"docker_host" bson:"docker_host"` MaxInstances int `json:"max_instances" bson:"max_instances"` Privileged bool `json:"privileged" bson:"privileged"`