Compare commits

...

4 Commits

2 changed files with 19 additions and 9 deletions

View File

@ -102,36 +102,43 @@ 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 len(apiName) > 0 && apiName != name {
if apiName != name {
continue
}
http.SetCookie(jc.ResponseWriter, &http.Cookie{
Name: routeableApi.AuthTokenName(),
Value: jwt,
Expires: time.Now().Add(24 * time.Hour),
MaxAge: int((24 * time.Hour).Seconds()),
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 len(apiName) > 0 && apiName != name {
if apiName != name {
continue
}
@ -158,23 +165,26 @@ func EchoAuthCookie(jc jape.Context, apiName string) {
http.SetCookie(jc.ResponseWriter, &http.Cookie{
Name: cookies[0].Name,
Value: cookies[0].Value,
Expires: exp.Time,
MaxAge: int(exp.Time.Sub(time.Now()).Seconds()),
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 len(apiName) > 0 && apiName != name {
if apiName != name {
continue
}
@ -190,7 +200,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, "")
account.SetAuthCookie(jc, jwt, a.Name())
account.SendJWT(jc, jwt)
jc.Encode(&LoginResponse{