Compare commits
No commits in common. "be7a7977aca912336f44ea1966c50b512a1da878" and "4a3028f61ae688558e1e59b52225d6a50c1adc96" have entirely different histories.
be7a7977ac
...
4a3028f61a
|
@ -102,43 +102,36 @@ func JWTVerifyToken(token string, domain string, privateKey ed25519.PrivateKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetAuthCookie(jc jape.Context, jwt string, apiName string) {
|
func SetAuthCookie(jc jape.Context, jwt string, apiName string) {
|
||||||
if len(apiName) == 0 {
|
|
||||||
panic("apiName is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, api := range apiRegistry.GetAllAPIs() {
|
for name, api := range apiRegistry.GetAllAPIs() {
|
||||||
routeableApi, ok := api.(router.RoutableAPI)
|
routeableApi, ok := api.(router.RoutableAPI)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiName != name {
|
if len(apiName) > 0 && apiName != name {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
http.SetCookie(jc.ResponseWriter, &http.Cookie{
|
http.SetCookie(jc.ResponseWriter, &http.Cookie{
|
||||||
Name: routeableApi.AuthTokenName(),
|
Name: routeableApi.AuthTokenName(),
|
||||||
Value: jwt,
|
Value: jwt,
|
||||||
MaxAge: int((24 * time.Hour).Seconds()),
|
Expires: time.Now().Add(24 * time.Hour),
|
||||||
Secure: true,
|
Secure: true,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
Domain: routeableApi.Domain(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func EchoAuthCookie(jc jape.Context, apiName string) {
|
func EchoAuthCookie(jc jape.Context, apiName string) {
|
||||||
if len(apiName) == 0 {
|
|
||||||
panic("apiName is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, api := range apiRegistry.GetAllAPIs() {
|
for name, api := range apiRegistry.GetAllAPIs() {
|
||||||
routeableApi, ok := api.(router.RoutableAPI)
|
routeableApi, ok := api.(router.RoutableAPI)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiName != name {
|
if len(apiName) > 0 && apiName != name {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,26 +158,23 @@ func EchoAuthCookie(jc jape.Context, apiName string) {
|
||||||
http.SetCookie(jc.ResponseWriter, &http.Cookie{
|
http.SetCookie(jc.ResponseWriter, &http.Cookie{
|
||||||
Name: cookies[0].Name,
|
Name: cookies[0].Name,
|
||||||
Value: cookies[0].Value,
|
Value: cookies[0].Value,
|
||||||
MaxAge: int(exp.Time.Sub(time.Now()).Seconds()),
|
Expires: exp.Time,
|
||||||
Secure: true,
|
Secure: true,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
Domain: cookies[0].Domain,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClearAuthCookie(jc jape.Context, apiName string) {
|
func ClearAuthCookie(jc jape.Context, apiName string) {
|
||||||
if len(apiName) == 0 {
|
|
||||||
panic("apiName is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
for name, api := range apiRegistry.GetAllAPIs() {
|
for name, api := range apiRegistry.GetAllAPIs() {
|
||||||
routeableApi, ok := api.(router.RoutableAPI)
|
routeableApi, ok := api.(router.RoutableAPI)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiName != name {
|
if len(apiName) > 0 && apiName != name {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +190,7 @@ func ClearAuthCookie(jc jape.Context, apiName string) {
|
||||||
Secure: true,
|
Secure: true,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
// Domain: "." + routeableApi.Domain(),
|
Domain: routeableApi.Domain(),
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ func (a AccountAPI) login(jc jape.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
account.SetAuthCookie(jc, jwt, a.Name())
|
account.SetAuthCookie(jc, jwt, "")
|
||||||
account.SendJWT(jc, jwt)
|
account.SendJWT(jc, jwt)
|
||||||
|
|
||||||
jc.Encode(&LoginResponse{
|
jc.Encode(&LoginResponse{
|
||||||
|
|
Loading…
Reference in New Issue