62384ab6f5
Copy the files from CentOS build. No changes are required to build the stx-oidc-client image within Debian build environment. The image is based on upstream golang. Remove oidc-client docker image build from CentOS Test Plan: PASS: private build of docker image PASS: review/compare content of docker image PASS: isolated run of docker image for exe sanity Story: 2009831 Task: 46463 Change-Id: Ic875337778947f4be05b6f5506302061b67799f5 Signed-off-by: Michel Thebeau <Michel.Thebeau@windriver.com>
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
// Initial file was taken from https://github.com/dexidp/dex/tree/master/cmd/example-app 2019
|
|
//
|
|
// Copyright (c) 2020 Wind River Systems, Inc.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
package main
|
|
|
|
import (
|
|
"html/template"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
type tokenTmplData struct {
|
|
IDToken string
|
|
AccessToken string
|
|
RefreshToken string
|
|
RedirectURL string
|
|
Claims string
|
|
}
|
|
|
|
var tokenTmpl = template.Must(template.New("token.html").Parse(`<html>
|
|
<head>
|
|
<style>
|
|
/* make pre wrap */
|
|
pre {
|
|
white-space: pre-wrap; /* css-3 */
|
|
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
|
|
white-space: -pre-wrap; /* Opera 4-6 */
|
|
white-space: -o-pre-wrap; /* Opera 7 */
|
|
word-wrap: break-word; /* Internet Explorer 5.5+ */
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<p> ID Token: <pre><code>{{ .IDToken }}</code></pre></p>
|
|
<p> Access Token: <pre><code>{{ .AccessToken }}</code></pre></p>
|
|
<p> Claims: <pre><code>{{ .Claims }}</code></pre></p>
|
|
{{ if .RefreshToken }}
|
|
<p> Refresh Token: <pre><code>{{ .RefreshToken }}</code></pre></p>
|
|
<form action="{{ .RedirectURL }}" method="post">
|
|
<input type="hidden" name="refresh_token" value="{{ .RefreshToken }}">
|
|
<input type="submit" value="Redeem refresh token">
|
|
</form>
|
|
{{ end }}
|
|
</body>
|
|
</html>
|
|
`))
|
|
|
|
func renderToken(w http.ResponseWriter, redirectURL, idToken, accessToken, refreshToken, claims string) {
|
|
renderTemplate(w, tokenTmpl, tokenTmplData{
|
|
IDToken: idToken,
|
|
AccessToken: accessToken,
|
|
RefreshToken: refreshToken,
|
|
RedirectURL: redirectURL,
|
|
Claims: claims,
|
|
})
|
|
}
|
|
|
|
func renderTemplate(w http.ResponseWriter, tmpl *template.Template, data interface{}) {
|
|
err := tmpl.Execute(w, data)
|
|
if err == nil {
|
|
return
|
|
}
|
|
|
|
switch err := err.(type) {
|
|
case *template.Error:
|
|
// An ExecError guarantees that Execute has not written to the underlying reader.
|
|
log.Printf("Error rendering template %s: %s", tmpl.Name(), err)
|
|
|
|
// TODO(ericchiang): replace with better internal server error.
|
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
|
default:
|
|
// An error with the underlying write, such as the connection being
|
|
// dropped. Ignore for now.
|
|
}
|
|
}
|