From 2d00363ee2513e0ed4fff894cc99aba88355bd3b Mon Sep 17 00:00:00 2001 From: the_aceix Date: Wed, 6 Dec 2023 12:09:20 +0000 Subject: [PATCH] fix(NET-678): fix context endpoint for sso exit gracefully on saas oauth login timeout --- cli/cmd/context/set.go | 10 +++++++--- cli/functions/http_client.go | 11 ++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cli/cmd/context/set.go b/cli/cmd/context/set.go index 0472b0847c..ba3f4de60f 100644 --- a/cli/cmd/context/set.go +++ b/cli/cmd/context/set.go @@ -36,19 +36,23 @@ var contextSetCmd = &cobra.Command{ } if !ctx.Saas { if ctx.Username == "" && ctx.MasterKey == "" && !ctx.SSO { - cmd.Usage() log.Fatal("Either username/password or master key is required") + cmd.Usage() } if ctx.Endpoint == "" { - cmd.Usage() log.Fatal("Endpoint is required when for self-hosted tenants") + cmd.Usage() } } else { if ctx.TenantId == "" { - cmd.Usage() log.Fatal("Tenant ID is required for SaaS tenants") + cmd.Usage() } ctx.Endpoint = fmt.Sprintf(functions.TenantUrlTemplate, tenantId) + if ctx.Username == "" && ctx.Password == "" && !ctx.SSO { + log.Fatal("Username/password is required for non-SSO SaaS contexts") + cmd.Usage() + } } config.SetContext(args[0], ctx) }, diff --git a/cli/functions/http_client.go b/cli/functions/http_client.go index a977f46867..4bff92cb62 100644 --- a/cli/functions/http_client.go +++ b/cli/functions/http_client.go @@ -22,7 +22,7 @@ import ( const ( ambBaseUrl = "https://api.accounts.netmaker.io" - TenantUrlTemplate = "api-%s.app.prod.netmaker.io" + TenantUrlTemplate = "https://api-%s.app.prod.netmaker.io" ambOauthWssUrl = "wss://api.accounts.netmaker.io/api/v1/auth/sso" ) @@ -126,7 +126,6 @@ func getAuthToken(ctx config.Context, force bool) string { if err != nil { log.Fatal(err) } - fmt.Println("supertoken acquired: ", sToken) authToken, _, err := tenantLogin(ctx, sToken) if err != nil { log.Fatal(err) @@ -292,8 +291,6 @@ func tenantLogin(ctx config.Context, sToken string) (string, string, error) { } req.Header.Add("Cookie", fmt.Sprintf("sAccessToken=%s", sToken)) - fmt.Println("sending req to tenant login url: ", url) - fmt.Println(req) res, err := client.Do(req) if err != nil { return "", "", err @@ -381,15 +378,15 @@ func handleServerSSORegisterConn(payload *models.SsoLoginReqDto, conn *websocket select { case <-done: slog.Info("wss phase finished") - case <-time.After(30 * time.Second): - slog.Info("authentiation timed out") - return "", nil case accessToken := <-dataCh: if accessToken == "" { slog.Info("error getting access token") return "", fmt.Errorf("error getting access token") } return accessToken, nil + case <-time.After(30 * time.Second): + slog.Error("authentiation timed out") + os.Exit(1) case <-interrupt: slog.Info("interrupt received, closing connection") // Cleanly close the connection by sending a close message and then