From 46e95f81849222c547a642fe285f74193b8f5362 Mon Sep 17 00:00:00 2001 From: Eleftheria Stein-Kousathana Date: Wed, 8 Nov 2023 15:39:27 +0100 Subject: [PATCH] Improve login success page Use embedded HTML page, instead of writing HTML in a string. --- cmd/cli/app/auth/auth_login.go | 12 ++++++-- cmd/cli/app/auth/html/login_success.html | 39 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 cmd/cli/app/auth/html/login_success.html diff --git a/cmd/cli/app/auth/auth_login.go b/cmd/cli/app/auth/auth_login.go index 4c566e7998..c3caeb71fc 100644 --- a/cmd/cli/app/auth/auth_login.go +++ b/cmd/cli/app/auth/auth_login.go @@ -23,6 +23,7 @@ package auth import ( "context" + _ "embed" "fmt" "net/http" "net/url" @@ -49,6 +50,9 @@ import ( pb "github.com/stacklok/minder/pkg/api/protobuf/go/minder/v1" ) +//go:embed html/login_success.html +var loginSuccessHtml []byte + func userRegistered(ctx context.Context, client pb.UserServiceClient) (bool, *pb.GetUserResponse, error) { res, err := client.GetUser(ctx, &pb.GetUserRequest{}) if err != nil { @@ -121,9 +125,13 @@ will be saved to $XDG_CONFIG_HOME/minder/credentials.json`, rp rp.RelyingParty) { tokenChan <- tokens - msg := "

Authentication successful

You may now close this tab and return to your terminal.
" // send a success message to the browser - fmt.Fprint(w, msg) + w.Header().Set("Content-Type", "text/html; charset=utf-8") + _, err := w.Write(loginSuccessHtml) + if err != nil { + // if we cannot display the success page, just print a success message + cli.PrintCmd(cmd, "Authentication Successful") + } } http.Handle("/login", rp.AuthURLHandler(stateFn, provider)) http.Handle(callbackPath, rp.CodeExchangeHandler(callback, provider)) diff --git a/cmd/cli/app/auth/html/login_success.html b/cmd/cli/app/auth/html/login_success.html new file mode 100644 index 0000000000..82bddc5ec9 --- /dev/null +++ b/cmd/cli/app/auth/html/login_success.html @@ -0,0 +1,39 @@ + + + + + + Authentication Successful + + + +
+

Authentication Successful

+

You can now close this window and return to the CLI.

+
+ +