📝 Roadmap
This commit is contained in:
26
pkg/internal/auth/http.go
Normal file
26
pkg/internal/auth/http.go
Normal file
@ -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()
|
||||
}
|
@ -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 {
|
||||
|
1
pkg/internal/auth/userinfo.go
Normal file
1
pkg/internal/auth/userinfo.go
Normal file
@ -0,0 +1 @@
|
||||
package auth
|
Reference in New Issue
Block a user