Skip to content

Commit

Permalink
Improve login success page (#1597)
Browse files Browse the repository at this point in the history
Use embedded HTML page, instead of writing HTML in a string.
  • Loading branch information
eleftherias authored Nov 8, 2023
1 parent 672a100 commit d375dcc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cmd/cli/app/auth/auth_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package auth

import (
"context"
_ "embed"
"fmt"
"net/http"
"net/url"
Expand All @@ -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 {
Expand Down Expand Up @@ -121,9 +125,13 @@ will be saved to $XDG_CONFIG_HOME/minder/credentials.json`,
rp rp.RelyingParty) {

tokenChan <- tokens
msg := "<div><h2>Authentication successful</h2><div>You may now close this tab and return to your terminal.</div></div>"
// 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))
Expand Down
39 changes: 39 additions & 0 deletions cmd/cli/app/auth/html/login_success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<!--
Copyright 2023 Stacklok, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Authentication Successful</title>
<style>
.main {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 20vh;
}

h1 {
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="main">
<h1>Authentication Successful</h1>
<p>You can now close this window and return to the CLI.</p>
</div>
</body>
</html>

0 comments on commit d375dcc

Please sign in to comment.