diff --git a/pkg/cmd/login/login.go b/pkg/cmd/login/login.go index bc6c6d7c0..16c44687f 100644 --- a/pkg/cmd/login/login.go +++ b/pkg/cmd/login/login.go @@ -40,23 +40,22 @@ const ( defaultClientID = "rhoas-cli-prod" ) -const PostLoginPage = ` - - - - -
-

Logged in to RHOAS. Return to your terminal to begin.

+// HTML template to show on the redirect page +const RedirectURLTemplate = ` + + + + Welcome to RHOAS + + +
+
+ +

Welcome to RHOAS

+
You have successfully logged in to the RHOAS CLI as %v. You may now close this tab and return to the command-line.
+
+ ` // When the value of the `--url` option is one of the keys of this map it will be replaced by the @@ -256,26 +255,25 @@ func runLogin(opts *Options) error { os.Exit(1) } - w.Header().Set("Content-Type", "text/html; charset=utf-8") - fmt.Fprintln(w, PostLoginPage) - accessTkn, _ := token.Parse(resp.OAuth2Token.AccessToken) tknClaims, _ := token.MapClaims(accessTkn) userName, ok := tknClaims["preferred_username"] - logger.Info("") - if !ok { - logger.Info("You are now logged in") - } else { - rawUsername := fmt.Sprintf("%v", userName) - logger.Infof("You are now logged in as %v", color.Info(rawUsername)) + var rawUsername string = "unknown" + if ok { + rawUsername = fmt.Sprintf("%v", userName) } + w.Header().Set("Content-Type", "text/html; charset=utf-8") + fmt.Fprintf(w, RedirectURLTemplate, rawUsername) + + logger.Infof("You are now logged in as %v", color.Info(rawUsername)) + logger.Info("") + cancel() }) if opts.printURL { - logger.Info("Open the following URL in your browser to login:") - logger.Info("") + logger.Info("Open the following URL in your browser to login:\n\n") fmt.Println(authCodeURL) } else { openBrowserExec, _ := browser.GetOpenBrowserCommand(authCodeURL)