Documentation
¶
Overview ¶
Package ldapauthfiber is Fiber middleware for github.com/ctolon/ldap-authenticator.
It is a separate module so that the root package can promise a single dependency and mean it. The policy — group requirements, status codes, response padding — lives in the httpauth package of the root module and is shared with the other framework adapters.
app := fiber.New()
app.Use(ldapauthfiber.BasicAuth(auth, httpauth.RequireAnyGroup("developers")))
app.Get("/me", func(c *fiber.Ctx) error {
return c.JSON(ldapauthfiber.MustIdentity(c))
})
Fiber is built on fasthttp, which also means this module does not build for the wasm targets that the rest of this repository does — fasthttp's listener has no implementation for them.
Fiber is built on fasthttp rather than net/http, so this adapter does not share the other three's request plumbing: it reads the Authorization header and the body itself, and writes the rejection through Fiber. The httpauth options that take an *http.Request — WithSkip and WithErrorHandler — therefore do nothing here. Skip with Fiber's own routing, and shape errors with a custom Fiber error handler.
Index ¶
- Constants
- func BasicAuth(auth ldapauth.Authenticator, opts ...httpauth.Option) fiber.Handler
- func IdentityFrom(c *fiber.Ctx) (ldapauth.Identity, bool)
- func LoginHandler(auth ldapauth.Authenticator, ...) fiber.Handler
- func MustIdentity(c *fiber.Ctx) ldapauth.Identity
- func PrincipalFrom(c *fiber.Ctx) (*ldapauth.Principal, bool)
Constants ¶
const ContextKey = "ldapauth.identity"
ContextKey is the Locals key the identity is stored under.
Variables ¶
This section is empty.
Functions ¶
func BasicAuth ¶
BasicAuth returns middleware that authenticates every request with HTTP Basic credentials.
func IdentityFrom ¶
IdentityFrom returns the identity the middleware authenticated.
func LoginHandler ¶
func LoginHandler( auth ldapauth.Authenticator, onSuccess func(c *fiber.Ctx, p ldapauth.Identity) error, opts ...httpauth.Option, ) fiber.Handler
LoginHandler returns a handler that reads credentials from the request — JSON body, form body, or Basic header — and hands the authenticated principal to onSuccess.
func MustIdentity ¶
MustIdentity returns the authenticated identity and panics if there is none, for handlers that are only ever mounted behind BasicAuth.
func PrincipalFrom ¶
PrincipalFrom returns the identity as the concrete ldapauth.Principal, for the common case where the mapper was not replaced and reading fields is nicer than calling accessors.
Types ¶
This section is empty.