Provide external apis for ability of auth

This commit is contained in:
2024-10-22 23:23:58 +08:00
parent 0f4112e08b
commit a1412acc90
7 changed files with 58 additions and 13 deletions

View File

@ -4,7 +4,7 @@ import (
"github.com/gofiber/fiber/v2"
)
func AuthContextMiddleware(c *fiber.Ctx) error {
func ContextMiddleware(c *fiber.Ctx) error {
atk := tokenExtract(c)
c.Locals("nex_in_token", atk)
@ -20,7 +20,7 @@ func AuthContextMiddleware(c *fiber.Ctx) error {
return c.Next()
}
func AuthMiddleware(c *fiber.Ctx) error {
func ValidatorMiddleware(c *fiber.Ctx) error {
if c.Locals("nex_principal") == nil {
err := c.Locals("nex_auth_error").(error)
return fiber.NewError(fiber.StatusUnauthorized, err.Error())

View File

@ -33,6 +33,7 @@ func userinfoFetch(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusUnauthorized, fmt.Sprintf("unable to load userinfo: %v", err))
}
userinfo := sec.NewUserInfoFromProto(resp.Info.Info)
c.Locals("nex_user", userinfo)
tk, err := IWriter.WriteUserInfoJwt(userinfo)
if err != nil {
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("unable to sign userinfo: %v", err))