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

Struct Middleware

samlsp/middleware.go:48–110  ·  view source on GitHub ↗

Middleware implements middleware than allows a web application to support SAML. It implements http.Handler so that it can provide the metadata and ACS endpoints, typically /saml/metadata and /saml/acs, respectively. It also provides middleware RequireAccount which redirects users to the auth proce

Source from the content-addressed store, hash-verified

46// SAML service provider already has a private key, we borrow that key
47// to sign the JWTs as well.
48type Middleware struct {
49 ServiceProvider saml.ServiceProvider
50 OnError func(w http.ResponseWriter, r *http.Request, err error)
51 Binding string // saml.HTTPRedirectBinding, saml.HTTPPostBinding or saml.HTTPPostSimpleSignBinding
52 ResponseBinding string // saml.HTTPPostBinding, saml.HTTPArtifactBinding or saml.HTTPPostSimpleSignBinding
53 RequestTracker RequestTracker
54 Session SessionProvider
55 AssertionHandler AssertionHandler
56
57 // LogoutRequestTracker tracks the LogoutRequests sent by
58 // HandleStartLogout, so that ServeSLO accepts only a LogoutResponse to
59 // one of them. It must not share pending requests with RequestTracker.
60 // SP initiated single logout fails if it is nil.
61 LogoutRequestTracker RequestTracker
62
63 // ScriptNonce, if set, is called when the middleware serves the
64 // auto-submitting HTML form of the HTTP-POST binding. A non-empty result
65 // is set as the nonce attribute of the form's <script> element, for
66 // applications whose own Content-Security-Policy allows scripts by nonce.
67 ScriptNonce func(r *http.Request) string
68
69 // FormReplayStore, if set, lets a POST request that starts the auth flow
70 // be posted again once the user has logged in. If it is nil, the
71 // default, the user is redirected to the URI of the request with a GET
72 // request, and the form is lost.
73 //
74 // The form is saved only if the browser says the request comes from a
75 // page on the same origin (by the Sec-Fetch-Site or Origin header), and
76 // only if the FormReplayStore accepts it. After login it is posted back
77 // by an auto-submitting form, which carries the new session cookie.
78 // Enable this only for forms that are safe to submit again, and keep
79 // validating them, CSRF tokens included, as usual.
80 //
81 // Forms are saved under the RelayState returned by the RequestTracker,
82 // which must be unique to each auth flow: a RelayStateFunc that returns
83 // a fixed value must not be used with FormReplayStore.
84 FormReplayStore FormReplayStore
85
86 // LogoutBinding is the binding preferred for sending logout messages to
87 // the IDP (LogoutRequests from HandleStartLogout, and LogoutResponses to
88 // IDP initiated logout): saml.HTTPRedirectBinding,
89 // saml.HTTPPostBinding or saml.HTTPPostSimpleSignBinding. It is used
90 // when the IDP metadata has a SingleLogoutService endpoint for it.
91 // Otherwise, and when it is empty, HTTP-Redirect is used if the IDP
92 // supports it, HTTP-POST otherwise. The HTTP-POST-SimpleSign binding
93 // signs messages with ServiceProvider.Key and SignatureMethod, which
94 // must be set.
95 //
96 // saml.SOAPBinding makes HandleStartLogout send its LogoutRequest from
97 // the server, signed with ServiceProvider.Key, when the IDP metadata has
98 // a SOAP SingleLogoutService endpoint (see HandleStartLogout). The
99 // LogoutResponses to IDP initiated logout are then sent with the
100 // default front-channel binding.
101 LogoutBinding string
102
103 // RequirePOSTToStartLogout makes HandleStartLogout refuse any method
104 // but POST with 405 Method Not Allowed. Logging out changes state, and
105 // a GET handler lets any other site log the user out with a link or an

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected