Skip to content

Commit

Permalink
Change authentication success page more descriptive (#312)
Browse files Browse the repository at this point in the history
* Refactor: rename to authcode_browser.go

* Change authentication success page more descriptive
  • Loading branch information
int128 authored Jun 23, 2020
1 parent 9e27385 commit 77a6b91
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/adaptors/oidcclient/oidcclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type GetTokenByAuthCodeInput struct {
PKCEParams pkce.Params
RedirectURLHostname string
AuthRequestExtraParams map[string]string
LocalServerSuccessHTML string
}

// TokenSet represents an output DTO of
Expand Down Expand Up @@ -85,6 +86,7 @@ func (c *client) GetTokenByAuthCode(ctx context.Context, in GetTokenByAuthCodeIn
LocalServerBindAddress: in.BindAddress,
LocalServerReadyChan: localServerReadyChan,
RedirectURLHostname: in.RedirectURLHostname,
LocalServerSuccessHTML: in.LocalServerSuccessHTML,
}
token, err := oauth2cli.GetToken(ctx, config)
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions pkg/templates/authcode_browser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package templates

// AuthCodeBrowserSuccessHTML is the success page on browser based authentication.
const AuthCodeBrowserSuccessHTML = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Authenticated</title>
<script>
window.close()
</script>
<style>
body {
background-color: #eee;
margin: 0;
padding: 0;
font-family: sans-serif;
}
.placeholder {
margin: 5em;
padding: 2em;
background-color: #fff;
border-radius: 1em;
}
</style>
</head>
<body>
<div class="placeholder">
<h1>Authenticated</h1>
<p>You have logged in to the cluster. You can close this window.</p>
</div>
</body>
</html>
`
17 changes: 17 additions & 0 deletions pkg/templates/httpserver/httpserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"log"
"net/http"

"github.com/int128/kubelogin/pkg/templates"
)

func main() {
http.HandleFunc("/AuthCodeBrowserSuccessHTML", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("content-type", "text/html")
_, _ = w.Write([]byte(templates.AuthCodeBrowserSuccessHTML))
})
log.Printf("http://localhost:8000/AuthCodeBrowserSuccessHTML")
log.Fatal(http.ListenAndServe("127.0.0.1:8000", nil))
}
6 changes: 6 additions & 0 deletions pkg/templates/package.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Package templates provides templates such as HTML and messages.
//
// You can preview HTML pages by running httpserver package.
// go run ./httpserver
//
package templates
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/int128/kubelogin/pkg/adaptors/oidcclient"
"github.com/int128/kubelogin/pkg/domain/oidc"
"github.com/int128/kubelogin/pkg/domain/pkce"
"github.com/int128/kubelogin/pkg/templates"
"golang.org/x/sync/errgroup"
"golang.org/x/xerrors"
)
Expand Down Expand Up @@ -39,6 +40,7 @@ func (u *AuthCode) Do(ctx context.Context, o *AuthCodeOption, client oidcclient.
PKCEParams: p,
RedirectURLHostname: o.RedirectURLHostname,
AuthRequestExtraParams: o.AuthRequestExtraParams,
LocalServerSuccessHTML: templates.AuthCodeBrowserSuccessHTML,
}
readyChan := make(chan string, 1)
defer close(readyChan)
Expand Down

0 comments on commit 77a6b91

Please sign in to comment.