github.com/crewjam/saml@v0.4.14/samlsp/request_tracker.go (about) 1 package samlsp 2 3 import ( 4 "net/http" 5 ) 6 7 // RequestTracker tracks pending authentication requests. 8 // 9 // There are two main reasons for this: 10 // 11 // 1. When the middleware initiates an authentication request it must track the original URL 12 // in order to redirect the user to the right place after the authentication completes. 13 // 14 // 2. After the authentication completes, we want to ensure that the user presenting the 15 // assertion is actually the one the request it, to mitigate request forgeries. 16 type RequestTracker interface { 17 // TrackRequest starts tracking the SAML request with the given ID. It returns an 18 // `index` that should be used as the RelayState in the SAMl request flow. 19 TrackRequest(w http.ResponseWriter, r *http.Request, samlRequestID string) (index string, err error) 20 21 // StopTrackingRequest stops tracking the SAML request given by index, which is a string 22 // previously returned from TrackRequest 23 StopTrackingRequest(w http.ResponseWriter, r *http.Request, index string) error 24 25 // GetTrackedRequests returns all the pending tracked requests 26 GetTrackedRequests(r *http.Request) []TrackedRequest 27 28 // GetTrackedRequest returns a pending tracked request. 29 GetTrackedRequest(r *http.Request, index string) (*TrackedRequest, error) 30 } 31 32 // TrackedRequest holds the data we store for each pending request. 33 type TrackedRequest struct { 34 Index string `json:"-"` 35 SAMLRequestID string `json:"id"` 36 URI string `json:"uri"` 37 } 38 39 // TrackedRequestCodec handles encoding and decoding of a TrackedRequest. 40 type TrackedRequestCodec interface { 41 // Encode returns an encoded string representing the TrackedRequest. 42 Encode(value TrackedRequest) (string, error) 43 44 // Decode returns a Tracked request from an encoded string. 45 Decode(signed string) (*TrackedRequest, error) 46 }