2022-04-26 22:30:39 +00:00
|
|
|
// Copyright 2022 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package login
|
|
|
|
|
|
|
|
import (
|
2022-04-28 16:11:51 +00:00
|
|
|
_ "embed"
|
|
|
|
"html/template"
|
2022-04-26 22:30:39 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"go.pinniped.dev/internal/oidc"
|
|
|
|
)
|
|
|
|
|
2022-04-28 16:11:51 +00:00
|
|
|
var (
|
|
|
|
//go:embed login_form.gohtml
|
|
|
|
rawHTMLTemplate string
|
|
|
|
)
|
|
|
|
|
|
|
|
type PageData struct {
|
|
|
|
State string
|
|
|
|
IDPName string
|
|
|
|
}
|
|
|
|
|
2022-04-26 22:30:39 +00:00
|
|
|
func NewGetHandler(upstreamIDPs oidc.UpstreamIdentityProvidersLister) HandlerFunc {
|
2022-04-28 19:07:04 +00:00
|
|
|
var parsedHTMLTemplate = template.Must(template.New("login_post.gohtml").Parse(rawHTMLTemplate))
|
2022-04-26 22:30:39 +00:00
|
|
|
return func(w http.ResponseWriter, r *http.Request, encodedState string, decodedState *oidc.UpstreamStateParamData) error {
|
2022-04-28 16:11:51 +00:00
|
|
|
err := parsedHTMLTemplate.Execute(w, &PageData{State: encodedState, IDPName: decodedState.UpstreamName})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-04-26 22:30:39 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|