Files
hanko/backend/utils/cookie.go
Stefan Jacobi 724013e56d feat(saml): implement enterprise saml feature
Co-authored-by: Stefan Jacobi <stefan.jacobi@adesso.de>
2023-10-18 10:50:58 +02:00

39 lines
772 B
Go

package utils
import (
"github.com/teamhanko/hanko/backend/config"
"net/http"
)
const (
HankoThirdpartyStateCookie = "hanko_thirdparty_state"
HankoTokenQuery = "hanko_token"
)
type CookieOptions struct {
MaxAge int
Path string
SameSite http.SameSite
}
func GenerateStateCookie(config *config.Config, name string, state string, options CookieOptions) *http.Cookie {
if options.Path == "" {
options.Path = "/"
}
if options.MaxAge == 0 {
options.MaxAge = 300
}
return &http.Cookie{
Name: name,
Value: state,
Path: options.Path,
Domain: config.Session.Cookie.Domain,
MaxAge: options.MaxAge,
Secure: config.Session.Cookie.Secure,
HttpOnly: config.Session.Cookie.HttpOnly,
SameSite: options.SameSite,
}
}