diff --git a/ROADMAP.md b/ROADMAP.md new file mode 100644 index 0000000..d071330 --- /dev/null +++ b/ROADMAP.md @@ -0,0 +1,16 @@ +# Roadmap + +The development progress and plan for Hypernet.Nexus + +- [x] Service discovery +- [x] Command system +- [x] High availability +- [x] Microservice gateway +- [ ] Authenticate (W.I.P) +- [ ] FastLSF (fast lua based serverless function) + +The goal of project Hypernet is going to replace the Hydrogen as Solar Network server-side software. +And the goal of this project is going to replace Hydrogen.Dealer as the core component of Solar Network. + +Other Hydrogen project will be refactored and upgraded to support Nexus as soon as the first stable version is released. +Some features will moved to command based api, such as daily sign in Passport which isn't in Nexus Standard and will be not in it. \ No newline at end of file diff --git a/pkg/internal/auth/http.go b/pkg/internal/auth/http.go new file mode 100644 index 0000000..302c477 --- /dev/null +++ b/pkg/internal/auth/http.go @@ -0,0 +1,26 @@ +package auth + +import "github.com/gofiber/fiber/v2" + +func SoftAuthMiddleware(c *fiber.Ctx) error { + atk := tokenExtract(c) + c.Locals("nex_token", atk) + + if claims, err := tokenRead(atk); err == nil && claims != nil { + c.Locals("nex_principal", claims) + // TODO fetch user info + } else if err != nil { + c.Locals("nex_auth_error", err) + } + + return c.Next() +} + +func HardAuthMiddleware(c *fiber.Ctx) error { + if c.Locals("nex_principal") == nil { + err := c.Locals("nex_auth_error").(error) + return fiber.NewError(fiber.StatusUnauthorized, err.Error()) + } + + return c.Next() +} diff --git a/pkg/internal/auth/token.go b/pkg/internal/auth/token.go index 3b7b9b7..106bc4e 100644 --- a/pkg/internal/auth/token.go +++ b/pkg/internal/auth/token.go @@ -8,28 +8,6 @@ import ( var JReader *sec.JwtReader -func SoftAuthMiddleware(c *fiber.Ctx) error { - atk := tokenExtract(c) - c.Locals("nex_token", atk) - - if claims, err := tokenRead(atk); err == nil && claims != nil { - c.Locals("nex_principal", claims) - } else if err != nil { - c.Locals("nex_auth_error", err) - } - - return c.Next() -} - -func HardAuthMiddleware(c *fiber.Ctx) error { - if c.Locals("nex_principal") == nil { - err := c.Locals("nex_auth_error").(error) - return fiber.NewError(fiber.StatusUnauthorized, err.Error()) - } - - return c.Next() -} - func tokenExtract(c *fiber.Ctx) string { var atk string if cookie := c.Cookies(sec.CookieAccessToken); len(cookie) > 0 { diff --git a/pkg/internal/auth/userinfo.go b/pkg/internal/auth/userinfo.go new file mode 100644 index 0000000..8832b06 --- /dev/null +++ b/pkg/internal/auth/userinfo.go @@ -0,0 +1 @@ +package auth