Compare commits
3 Commits
9e5d996f20
...
040c662826
Author | SHA1 | Date |
---|---|---|
|
040c662826 | |
|
66f73d1a53 | |
|
48dc1b9be0 |
|
@ -8,6 +8,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/samber/lo"
|
||||||
|
|
||||||
"go.sia.tech/jape"
|
"go.sia.tech/jape"
|
||||||
|
|
||||||
"git.lumeweb.com/LumeWeb/portal/api/router"
|
"git.lumeweb.com/LumeWeb/portal/api/router"
|
||||||
|
@ -114,6 +116,7 @@ func SetAuthCookie(jc jape.Context, jwt string, apiName string) {
|
||||||
Name: routeableApi.AuthTokenName(),
|
Name: routeableApi.AuthTokenName(),
|
||||||
Value: jwt,
|
Value: jwt,
|
||||||
Expires: time.Now().Add(24 * time.Hour),
|
Expires: time.Now().Add(24 * time.Hour),
|
||||||
|
Secure: true,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
Domain: routeableApi.Domain(),
|
Domain: routeableApi.Domain(),
|
||||||
|
@ -121,6 +124,29 @@ func SetAuthCookie(jc jape.Context, jwt string, apiName string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func EchoAuthCookie(jc jape.Context, apiName string) {
|
||||||
|
for name, api := range apiRegistry.GetAllAPIs() {
|
||||||
|
routeableApi, ok := api.(router.RoutableAPI)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(apiName) > 0 && apiName != name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
cookies := lo.Filter(jc.Request.Cookies(), func(item *http.Cookie, _ int) bool {
|
||||||
|
return item.Name == routeableApi.AuthTokenName()
|
||||||
|
})
|
||||||
|
|
||||||
|
if len(cookies) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
http.SetCookie(jc.ResponseWriter, cookies[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func ClearAuthCookie(jc jape.Context, apiName string) {
|
func ClearAuthCookie(jc jape.Context, apiName string) {
|
||||||
for name, api := range apiRegistry.GetAllAPIs() {
|
for name, api := range apiRegistry.GetAllAPIs() {
|
||||||
routeableApi, ok := api.(router.RoutableAPI)
|
routeableApi, ok := api.(router.RoutableAPI)
|
||||||
|
|
|
@ -287,6 +287,7 @@ func (a AccountAPI) passwordResetConfirm(jc jape.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AccountAPI) ping(jc jape.Context) {
|
func (a AccountAPI) ping(jc jape.Context) {
|
||||||
|
account.EchoAuthCookie(jc, a.Name())
|
||||||
jc.Encode(&PongResponse{
|
jc.Encode(&PongResponse{
|
||||||
Ping: "pong",
|
Ping: "pong",
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue