Skip to content

Commit

Permalink
fix(NET-678): fix context endpoint for sso
Browse files Browse the repository at this point in the history
exit gracefully on saas oauth login timeout
  • Loading branch information
Aceix committed Dec 7, 2023
1 parent 10e6363 commit 2d00363
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 7 additions & 3 deletions cli/cmd/context/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
Expand Down
11 changes: 4 additions & 7 deletions cli/functions/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2d00363

Please sign in to comment.