diff --git a/web/auth/authenticate.go b/web/auth/authenticate.go index 2df1cd8..1a9613f 100644 --- a/web/auth/authenticate.go +++ b/web/auth/authenticate.go @@ -14,6 +14,30 @@ import ( "golang.org/x/crypto/bcrypt" ) +type ProtectBuilder struct { + c *fiber.Ctx + types []PayloadType + scopes []string +} + +func NewProtect(c *fiber.Ctx) *ProtectBuilder { + return &ProtectBuilder{c, []PayloadType{}, []string{}} +} + +func (p *ProtectBuilder) Payload(types ...PayloadType) *ProtectBuilder { + p.types = types + return p +} + +func (p *ProtectBuilder) Scopes(scopes ...string) *ProtectBuilder { + p.scopes = scopes + return p +} + +func (p *ProtectBuilder) Do() (*Context, error) { + return Protect(p.c, p.types, p.scopes) +} + func Protect(c *fiber.Ctx, types []PayloadType, permissions []string) (*Context, error) { // 获取令牌 var header = c.Get("Authorization")