crewjam/saml

Override Session Provider to create custom cookies

UnderratedNorf opened this issue · 0 comments

I want to create my own JWT tokens after receiving the assertion. How can I override the SessionProvider?


func CustomSessionProvider(opts Options) CookieSessionProvider {
	return CookieSessionProvider{
		Name:     "splunkbase_test",
		Domain:   opts.URL.Host,
		MaxAge:   defaultSessionMaxAge,
		HTTPOnly: true,
		Secure:   opts.URL.Scheme == "https",
		SameSite: opts.CookieSameSite,
		Codec:    DefaultSessionCodec(opts),
	}
}


// Initialize SAML middleware
samlSP, _ := samlsp.New(samlsp.Options{
	URL:         *rootURL,
	Key:         keyPair.PrivateKey.(*rsa.PrivateKey),
	Certificate: keyPair.Leaf,
	IDPMetadata: idpMetadata,
})

customSession := CustomSessionProvider(Options{
	URL:         *rootURL,
	Key:         keyPair.PrivateKey.(*rsa.PrivateKey),
	Certificate: keyPair.Leaf,
	IDPMetadata: idpMetadata,
})

samlSP.Session = customSession

Error : cannot use customSession (variable of type CookieSessionProvider) as samlsp.SessionProvider value in assignment: CookieSessionProvider does not implement samlsp.SessionProvider (wrong type for method GetSession) have GetSession(r *http.Request) (Session, error) want GetSession(r *http.Request) (samlsp.Session, error)

I have copied the session_cookie.go, session_jwt.go and session.go into my project just to see how to override the session provider for the middleware. Not sure what the correct approach is. I want to create my own tokens and put custom assertion data into it, instead of the default.