Skip to content

Commit e074531

Browse files
authored
idp: make response form customizable (crewjam#601)
1 parent 89d1a36 commit e074531

4 files changed

+19
-13
lines changed

identity_provider.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
"encoding/base64"
99
"encoding/xml"
1010
"fmt"
11+
"html/template"
1112
"io"
1213
"net/http"
1314
"net/url"
1415
"os"
1516
"regexp"
1617
"strconv"
17-
"text/template"
1818
"time"
1919

2020
"github.com/beevik/etree"
@@ -108,6 +108,7 @@ type IdentityProvider struct {
108108
AssertionMaker AssertionMaker
109109
SignatureMethod string
110110
ValidDuration *time.Duration
111+
ResponseFormTemplate *template.Template
111112
}
112113

113114
// Metadata returns the metadata structure for this identity provider.
@@ -942,6 +943,16 @@ func (req *IdpAuthnRequest) PostBinding() (IdpAuthnRequestForm, error) {
942943
return form, nil
943944
}
944945

946+
var defaultResponseFormTemplate = template.Must(template.New("saml-post-form").Parse(`<html>` +
947+
`<form method="post" action="{{.URL}}" id="SAMLResponseForm">` +
948+
`<input type="hidden" name="SAMLResponse" value="{{.SAMLResponse}}" />` +
949+
`<input type="hidden" name="RelayState" value="{{.RelayState}}" />` +
950+
`<input id="SAMLSubmitButton" type="submit" value="Continue" />` +
951+
`</form>` +
952+
`<script>document.getElementById('SAMLSubmitButton').style.visibility='hidden';</script>` +
953+
`<script>document.getElementById('SAMLResponseForm').submit();</script>` +
954+
`</html>`))
955+
945956
// WriteResponse writes the `Response` to the http.ResponseWriter. If
946957
// `Response` is not already set, it calls MakeResponse to produce it.
947958
func (req *IdpAuthnRequest) WriteResponse(w http.ResponseWriter) error {
@@ -950,15 +961,10 @@ func (req *IdpAuthnRequest) WriteResponse(w http.ResponseWriter) error {
950961
return err
951962
}
952963

953-
tmpl := template.Must(template.New("saml-post-form").Parse(`<html>` +
954-
`<form method="post" action="{{.URL}}" id="SAMLResponseForm">` +
955-
`<input type="hidden" name="SAMLResponse" value="{{.SAMLResponse}}" />` +
956-
`<input type="hidden" name="RelayState" value="{{.RelayState}}" />` +
957-
`<input id="SAMLSubmitButton" type="submit" value="Continue" />` +
958-
`</form>` +
959-
`<script>document.getElementById('SAMLSubmitButton').style.visibility='hidden';</script>` +
960-
`<script>document.getElementById('SAMLResponseForm').submit();</script>` +
961-
`</html>`))
964+
tmpl := req.IDP.ResponseFormTemplate
965+
if tmpl == nil {
966+
tmpl = defaultResponseFormTemplate
967+
}
962968

963969
buf := bytes.NewBuffer(nil)
964970
if err := tmpl.Execute(buf, form); err != nil {

0 commit comments

Comments
 (0)