@@ -8,13 +8,13 @@ import (
8
8
"encoding/base64"
9
9
"encoding/xml"
10
10
"fmt"
11
+ "html/template"
11
12
"io"
12
13
"net/http"
13
14
"net/url"
14
15
"os"
15
16
"regexp"
16
17
"strconv"
17
- "text/template"
18
18
"time"
19
19
20
20
"github.com/beevik/etree"
@@ -108,6 +108,7 @@ type IdentityProvider struct {
108
108
AssertionMaker AssertionMaker
109
109
SignatureMethod string
110
110
ValidDuration * time.Duration
111
+ ResponseFormTemplate * template.Template
111
112
}
112
113
113
114
// Metadata returns the metadata structure for this identity provider.
@@ -942,6 +943,16 @@ func (req *IdpAuthnRequest) PostBinding() (IdpAuthnRequestForm, error) {
942
943
return form , nil
943
944
}
944
945
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
+
945
956
// WriteResponse writes the `Response` to the http.ResponseWriter. If
946
957
// `Response` is not already set, it calls MakeResponse to produce it.
947
958
func (req * IdpAuthnRequest ) WriteResponse (w http.ResponseWriter ) error {
@@ -950,15 +961,10 @@ func (req *IdpAuthnRequest) WriteResponse(w http.ResponseWriter) error {
950
961
return err
951
962
}
952
963
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
+ }
962
968
963
969
buf := bytes .NewBuffer (nil )
964
970
if err := tmpl .Execute (buf , form ); err != nil {
0 commit comments