Fix some errors and pass state as form element

Signed-off-by: Margo Crawford <margaretc@vmware.com>
This commit is contained in:
Margo Crawford 2022-04-28 12:07:04 -07:00
parent 07b2306254
commit 453c69af7d
3 changed files with 18 additions and 13 deletions

View File

@ -16,16 +16,14 @@ var (
rawHTMLTemplate string
)
var parsedHTMLTemplate = template.Must(template.New("login_post.gohtml").Parse(rawHTMLTemplate))
type PageData struct {
State string
IDPName string
}
func NewGetHandler(upstreamIDPs oidc.UpstreamIdentityProvidersLister) HandlerFunc {
var parsedHTMLTemplate = template.Must(template.New("login_post.gohtml").Parse(rawHTMLTemplate))
return func(w http.ResponseWriter, r *http.Request, encodedState string, decodedState *oidc.UpstreamStateParamData) error {
err := parsedHTMLTemplate.Execute(w, &PageData{State: encodedState, IDPName: decodedState.UpstreamName})
if err != nil {
return err

View File

@ -1,3 +1,6 @@
// Copyright 2022 the Pinniped contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package login
import (
@ -22,19 +25,23 @@ func TestGetLogin(t *testing.T) {
<h1>Pinniped</h1>
<p>some-ldap-idp</p>
<form action="/login?state=foo" method="post">
<form action="/login" method="post">
<div>
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Username" name="uname" required>
<label for="username"><b>Username</b></label>
<input type="text" placeholder="Username" name="username" id="username" required>
</div>
<div>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Password" name="psw" required>
<label for="password"><b>Password</b></label>
<input type="password" placeholder="Password" name="password" id="password" required>
</div>
<button type="submit">Login</button>
<div>
<input type="hidden" name="state" id="state" value="foo">
</div>
<button type="submit" name="submit" id="submit">Login</button>
</form>

View File

@ -8,15 +8,15 @@ SPDX-License-Identifier: Apache-2.0
<h1>Pinniped</h1>
<p>{{ .IDPName }}</p>
<form action="/login?state={{.State}}" method="post">
<form action="/login" method="post">
<div>
<label for="uname"><b>Username</b></label>
<label for="username"><b>Username</b></label>
<input type="text" placeholder="Username" name="username" id="username" required>
</div>
<div>
<label for="psw"><b>Password</b></label>
<label for="password"><b>Password</b></label>
<input type="password" placeholder="Password" name="password" id="password" required>
</div>
@ -24,7 +24,7 @@ SPDX-License-Identifier: Apache-2.0
<input type="hidden" name="state" id="state" value="{{.State}}">
</div>
<button name="submit" id="submit" type="submit">Login</button>
<button type="submit" name="submit" id="submit">Login</button>
</form>