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

Method CreateSession

samlsp/session_cookie.go:30–57  ·  view source on GitHub ↗

CreateSession is called when we have received a valid SAML assertion and should create a new session and modify the http response accordingly, e.g. by setting a cookie.

(w http.ResponseWriter, r *http.Request, assertion *saml.Assertion)

Source from the content-addressed store, hash-verified

28// should create a new session and modify the http response accordingly, e.g. by
29// setting a cookie.
30func (c CookieSessionProvider) CreateSession(w http.ResponseWriter, r *http.Request, assertion *saml.Assertion) error {
31 // Cookies should not have the port attached to them so strip it off
32 if domain, _, err := net.SplitHostPort(c.Domain); err == nil {
33 c.Domain = domain
34 }
35
36 session, err := c.Codec.New(assertion)
37 if err != nil {
38 return err
39 }
40
41 value, err := c.Codec.Encode(session)
42 if err != nil {
43 return err
44 }
45
46 http.SetCookie(w, &http.Cookie{
47 Name: c.Name,
48 Domain: c.Domain,
49 Value: value,
50 MaxAge: int(c.MaxAge.Seconds()),
51 HttpOnly: c.HTTPOnly,
52 Secure: c.Secure || r.URL.Scheme == "https",
53 SameSite: c.SameSite,
54 Path: "/",
55 })
56 return nil
57}
58
59// DeleteSession is called to modify the response such that it removed the current
60// session, e.g. by deleting a cookie.

Callers 1

TestCookieSameSiteFunction · 0.95

Calls 2

NewMethod · 0.65
EncodeMethod · 0.65

Tested by 1

TestCookieSameSiteFunction · 0.76