MCPcopy Create free account
hub / github.com/crewjam/saml / sendLoginForm

Method sendLoginForm

samlidp/session.go:105–132  ·  view source on GitHub ↗

sendLoginForm produces a form which requests a username and password and directs the user back to the IDP authorize URL to restart the SAML login flow, this time establishing a session based on the credentials that were provided.

(w http.ResponseWriter, r *http.Request, req *saml.IdpAuthnRequest, toast string)

Source from the content-addressed store, hash-verified

103// back to the IDP authorize URL to restart the SAML login flow, this time establishing a
104// session based on the credentials that were provided.
105func (s *Server) sendLoginForm(w http.ResponseWriter, r *http.Request, req *saml.IdpAuthnRequest, toast string) {
106 tmpl := template.Must(template.New("saml-post-form").Parse(`` +
107 `<html>` +
108 `<p>{{.Toast}}</p>` +
109 `<form method="post" action="{{.URL}}">` +
110 `<input type="text" name="user" placeholder="user" value="" />` +
111 `<input type="password" name="password" placeholder="password" value="" />` +
112 `<input type="hidden" name="SAMLRequest" value="{{.SAMLRequest}}" />` +
113 `<input type="hidden" name="RelayState" value="{{.RelayState}}" />` +
114 `<input type="submit" value="Log In" />` +
115 `</form>` +
116 `</html>`))
117 data := struct {
118 Toast string
119 URL string
120 SAMLRequest string
121 RelayState string
122 }{
123 Toast: toast,
124 URL: req.IDP.SSOURL.String(),
125 SAMLRequest: base64.StdEncoding.EncodeToString(req.RequestBuffer),
126 RelayState: req.RelayState,
127 }
128
129 if err := tmpl.Execute(w, data); err != nil {
130 panic(err)
131 }
132}
133
134// HandleLogin handles the `POST /login` and `GET /login` forms. If credentials are present
135// in the request body, then they are validated. For valid credentials, the response is a

Callers 1

GetSessionMethod · 0.95

Calls 2

StringMethod · 0.80
NewMethod · 0.65

Tested by

no test coverage detected