Fix/cookie host (#76)

* fix: cookie host

* feat: add test for url utils

* fix: url test

* fix: multi domain cookie if allowed
This commit is contained in:
Lakhan Samani
2021-12-11 06:41:35 +05:30
committed by GitHub
parent 74a551ae09
commit 00565c8717
5 changed files with 41 additions and 4 deletions

View File

@@ -11,9 +11,14 @@ func SetCookie(gc *gin.Context, token string) {
secure := true
httpOnly := true
host := GetHostName(constants.AUTHORIZER_URL)
domain := GetDomainName(constants.AUTHORIZER_URL)
if domain != "localhost" {
domain = "." + domain
}
gc.SetSameSite(http.SameSiteNoneMode)
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", host, secure, httpOnly)
gc.SetCookie(constants.COOKIE_NAME+"-client", token, 3600, "/", domain, secure, httpOnly)
}
func GetCookie(gc *gin.Context) (string, error) {
@@ -29,8 +34,13 @@ func DeleteCookie(gc *gin.Context) {
secure := true
httpOnly := true
host := GetHostName(constants.AUTHORIZER_URL)
host := GetDomainName(constants.AUTHORIZER_URL)
domain := GetDomainName(constants.AUTHORIZER_URL)
if domain != "localhost" {
domain = "." + domain
}
gc.SetSameSite(http.SameSiteNoneMode)
gc.SetCookie(constants.COOKIE_NAME, "", -1, "/", host, secure, httpOnly)
gc.SetCookie(constants.COOKIE_NAME+"-client", "", -1, "/", domain, secure, httpOnly)
}