Fix cookie not set on custom domain
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -95,10 +95,19 @@ func authTokenHandler(trustSvc *trust.Service, trustAuthCfg TrustAuthConfig) htt
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine cookie domain: use custom domain if present, otherwise use configured domain
|
||||||
|
cookieDomain := trustAuthCfg.CookieDomain
|
||||||
|
if _, ok := GetCustomDomainOrganizationID(r.Context()); ok {
|
||||||
|
// On custom domain, use the request host
|
||||||
|
if r.TLS != nil && r.TLS.ServerName != "" {
|
||||||
|
cookieDomain = r.TLS.ServerName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cookie := &http.Cookie{
|
cookie := &http.Cookie{
|
||||||
Name: trustAuthCfg.CookieName,
|
Name: trustAuthCfg.CookieName,
|
||||||
Value: tokenString,
|
Value: tokenString,
|
||||||
Domain: trustAuthCfg.CookieDomain,
|
Domain: cookieDomain,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
MaxAge: int(trustAuthCfg.CookieDuration / time.Second),
|
MaxAge: int(trustAuthCfg.CookieDuration / time.Second),
|
||||||
Secure: true,
|
Secure: true,
|
||||||
@@ -135,10 +144,19 @@ func validateTrustCenterAccessToken(ctx context.Context, trustSvc *trust.Service
|
|||||||
|
|
||||||
func trustCenterLogoutHandler(authCfg console_v1.AuthConfig, trustAuthCfg TrustAuthConfig) http.HandlerFunc {
|
func trustCenterLogoutHandler(authCfg console_v1.AuthConfig, trustAuthCfg TrustAuthConfig) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// Determine cookie domain: use custom domain if present, otherwise use configured domain
|
||||||
|
cookieDomain := trustAuthCfg.CookieDomain
|
||||||
|
if _, ok := GetCustomDomainOrganizationID(r.Context()); ok {
|
||||||
|
// On custom domain, use the request host
|
||||||
|
if r.TLS != nil && r.TLS.ServerName != "" {
|
||||||
|
cookieDomain = r.TLS.ServerName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: trustAuthCfg.CookieName,
|
Name: trustAuthCfg.CookieName,
|
||||||
Value: "",
|
Value: "",
|
||||||
Domain: trustAuthCfg.CookieDomain,
|
Domain: cookieDomain,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
MaxAge: -1,
|
MaxAge: -1,
|
||||||
Secure: true,
|
Secure: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user