Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve login success page #1597

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>