refactor: set auth cookie for every api, and optionally pass a specific api name to only set instead
This commit is contained in:
parent
325a368dea
commit
2a8c036dc6
|
@ -8,6 +8,10 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.lumeweb.com/LumeWeb/portal/api/router"
|
||||||
|
|
||||||
|
apiRegistry "git.lumeweb.com/LumeWeb/portal/api/registry"
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt/v5"
|
"github.com/golang-jwt/jwt/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -93,7 +97,17 @@ func JWTVerifyToken(token string, domain string, privateKey ed25519.PrivateKey,
|
||||||
return claim, err
|
return claim, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetAuthCookie(w http.ResponseWriter, name, token string) {
|
func SetAuthCookie(w http.ResponseWriter, token string, apiName string) {
|
||||||
|
for name, api := range apiRegistry.GetAllAPIs() {
|
||||||
|
routeableApi, ok := api.(router.RoutableAPI)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(apiName) > 0 && apiName != name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: name,
|
Name: name,
|
||||||
Value: token,
|
Value: token,
|
||||||
|
@ -101,5 +115,7 @@ func SetAuthCookie(w http.ResponseWriter, name, token string) {
|
||||||
Secure: true,
|
Secure: true,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Path: "/",
|
Path: "/",
|
||||||
|
Domain: routeableApi.Domain(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue