Compare commits
4 Commits
4a3028f61a
...
be7a7977ac
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | be7a7977ac | |
Derrick Hammer | ee8fa2b98d | |
Derrick Hammer | ad8de8f5a1 | |
Derrick Hammer | 9587ef4941 |
|
@ -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(),
|
||||
})
|
||||
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
|
|
Loading…
Reference in New Issue