Documentation
¶
Overview ¶
Package ldapauthecho is Echo 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 — realms, group requirements, status codes, response padding — lives in the httpauth package of the root module and is shared with the other framework adapters.
e := echo.New()
e.Use(ldapauthecho.BasicAuth(auth, httpauth.RequireAnyGroup("developers")))
e.GET("/me", func(c echo.Context) error {
return c.JSON(200, ldapauthecho.MustIdentity(c))
})
Index ¶
- Constants
- func BasicAuth(auth ldapauth.Authenticator, opts ...httpauth.Option) echo.MiddlewareFunc
- func IdentityFrom(c echo.Context) (ldapauth.Identity, bool)
- func LoginHandler(auth ldapauth.Authenticator, ...) echo.HandlerFunc
- func MustIdentity(c echo.Context) ldapauth.Identity
- func PrincipalFrom(c echo.Context) (*ldapauth.Principal, bool)
Constants ¶
const ContextKey = "ldapauth.identity"
ContextKey is the key the identity is stored under in the Echo context, for handlers that would rather use c.Get than the request context.
Variables ¶
This section is empty.
Functions ¶
func BasicAuth ¶
func BasicAuth(auth ldapauth.Authenticator, opts ...httpauth.Option) echo.MiddlewareFunc
BasicAuth returns middleware that authenticates every request with HTTP Basic credentials.
It writes the rejection itself and returns nil rather than returning an echo.HTTPError, so that Echo's error handler cannot turn a bare 401 into a response body describing why the login failed.
func IdentityFrom ¶
IdentityFrom returns the identity the middleware authenticated.
func LoginHandler ¶
func LoginHandler( auth ldapauth.Authenticator, onSuccess func(c echo.Context, p ldapauth.Identity) error, opts ...httpauth.Option, ) echo.HandlerFunc
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.