fiber_docs/security/security.go

34 lines
705 B
Go
Raw Normal View History

2023-04-11 20:43:48 +00:00
package security
import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/gofiber/fiber/v2"
)
type AuthType string
const (
Credentials = "credentials"
BasicAuth AuthType = "BasicAuth"
BearerAuth AuthType = "BearerAuth"
ApiKeyAuth AuthType = "ApiKeyAuth"
OpenIDAuth AuthType = "OpenIDAuth"
OAuth2Auth AuthType = "OAuth2Auth"
CookieAuth AuthType = "CookieAuth"
)
type ISecurity interface {
Authorize(c *fiber.Ctx) error
Callback(c *fiber.Ctx, credentials interface{})
Provider() AuthType
Scheme() *openapi3.SecurityScheme
}
type Security struct {
ISecurity
}
func (s *Security) Callback(c *fiber.Ctx, credentials interface{}) {
c.Locals(Credentials, credentials)
}