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

View File

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

View File

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