Compare commits

..

No commits in common. "be7a7977aca912336f44ea1966c50b512a1da878" and "4a3028f61ae688558e1e59b52225d6a50c1adc96" have entirely different histories.

2 changed files with 9 additions and 19 deletions

View File

@ -102,43 +102,36 @@ func JWTVerifyToken(token string, domain string, privateKey ed25519.PrivateKey,
}
func SetAuthCookie(jc jape.Context, jwt string, apiName string) {
if len(apiName) == 0 {
panic("apiName is required")
}
for name, api := range apiRegistry.GetAllAPIs() {
routeableApi, ok := api.(router.RoutableAPI)
if !ok {
continue
}
if apiName != name {
if len(apiName) > 0 && apiName != name {
continue
}
http.SetCookie(jc.ResponseWriter, &http.Cookie{
Name: routeableApi.AuthTokenName(),
Value: jwt,
MaxAge: int((24 * time.Hour).Seconds()),
Expires: time.Now().Add(24 * time.Hour),
Secure: true,
HttpOnly: true,
Path: "/",
Domain: routeableApi.Domain(),
})
}
}
func EchoAuthCookie(jc jape.Context, apiName string) {
if len(apiName) == 0 {
panic("apiName is required")
}
for name, api := range apiRegistry.GetAllAPIs() {
routeableApi, ok := api.(router.RoutableAPI)
if !ok {
continue
}
if apiName != name {
if len(apiName) > 0 && apiName != name {
continue
}
@ -165,26 +158,23 @@ func EchoAuthCookie(jc jape.Context, apiName string) {
http.SetCookie(jc.ResponseWriter, &http.Cookie{
Name: cookies[0].Name,
Value: cookies[0].Value,
MaxAge: int(exp.Time.Sub(time.Now()).Seconds()),
Expires: exp.Time,
Secure: true,
HttpOnly: true,
Path: "/",
Domain: cookies[0].Domain,
})
}
}
func ClearAuthCookie(jc jape.Context, apiName string) {
if len(apiName) == 0 {
panic("apiName is required")
}
for name, api := range apiRegistry.GetAllAPIs() {
routeableApi, ok := api.(router.RoutableAPI)
if !ok {
continue
}
if apiName != name {
if len(apiName) > 0 && apiName != name {
continue
}
@ -200,7 +190,7 @@ func ClearAuthCookie(jc jape.Context, apiName string) {
Secure: true,
HttpOnly: true,
Path: "/",
// Domain: "." + routeableApi.Domain(),
Domain: routeableApi.Domain(),
})
}

View File

@ -120,7 +120,7 @@ func (a AccountAPI) login(jc jape.Context) {
return
}
account.SetAuthCookie(jc, jwt, a.Name())
account.SetAuthCookie(jc, jwt, "")
account.SendJWT(jc, jwt)
jc.Encode(&LoginResponse{