2021-07-14 18:43:19 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2021-07-22 00:54:15 +00:00
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
|
2021-07-23 16:27:44 +00:00
|
|
|
"github.com/authorizerdev/authorizer/server/constants"
|
2021-07-14 18:43:19 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func SetCookie(gc *gin.Context, token string) {
|
|
|
|
secure := true
|
|
|
|
httpOnly := true
|
|
|
|
|
|
|
|
if !constants.IS_PROD {
|
|
|
|
secure = false
|
|
|
|
}
|
2021-07-22 00:54:15 +00:00
|
|
|
u, err := url.Parse(constants.SERVER_URL)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("error getting server host")
|
|
|
|
}
|
|
|
|
gc.SetSameSite(http.SameSiteNoneMode)
|
|
|
|
gc.SetCookie(constants.COOKIE_NAME, token, 3600, "/", u.Hostname(), secure, httpOnly)
|
2021-07-14 18:43:19 +00:00
|
|
|
}
|
2021-07-15 09:43:00 +00:00
|
|
|
|
|
|
|
func DeleteCookie(gc *gin.Context) {
|
|
|
|
secure := true
|
|
|
|
httpOnly := true
|
|
|
|
|
|
|
|
if !constants.IS_PROD {
|
|
|
|
secure = false
|
|
|
|
}
|
|
|
|
|
2021-07-22 00:54:15 +00:00
|
|
|
u, err := url.Parse(constants.SERVER_URL)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("error getting server host")
|
|
|
|
}
|
|
|
|
gc.SetSameSite(http.SameSiteNoneMode)
|
|
|
|
|
|
|
|
gc.SetCookie(constants.COOKIE_NAME, "", -1, "/", u.Hostname(), secure, httpOnly)
|
2021-07-15 09:43:00 +00:00
|
|
|
}
|