Documentation
¶
Overview ¶
Package ldapauthgin is Gin 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: importing ldapauth never puts Gin in your build graph. 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, so behaviour cannot drift between them.
r := gin.New()
r.Use(ldapauthgin.BasicAuth(auth, httpauth.RequireAnyGroup("developers")))
r.GET("/me", func(c *gin.Context) {
c.JSON(200, ldapauthgin.MustIdentity(c))
})
Index ¶
- Constants
- func BasicAuth(auth ldapauth.Authenticator, opts ...httpauth.Option) gin.HandlerFunc
- func IdentityFrom(c *gin.Context) (ldapauth.Identity, bool)
- func LoginHandler(auth ldapauth.Authenticator, ...) gin.HandlerFunc
- func MustIdentity(c *gin.Context) ldapauth.Identity
- func PrincipalFrom(c *gin.Context) (*ldapauth.Principal, bool)
Constants ¶
const ContextKey = "ldapauth.identity"
ContextKey is the key the identity is stored under in the Gin 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) gin.HandlerFunc
BasicAuth returns middleware that authenticates every request with HTTP Basic credentials, aborting with 401, 403, or 503 as appropriate and otherwise passing the principal to the handlers behind it.
An option that does not validate panics: middleware is wired at startup, and there is nowhere to return an error to.
func IdentityFrom ¶
IdentityFrom returns the identity the middleware authenticated.
func LoginHandler ¶
func LoginHandler( auth ldapauth.Authenticator, onSuccess func(c *gin.Context, p ldapauth.Identity), opts ...httpauth.Option, ) gin.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.
It issues no session and no token. What a successful login becomes is the application's decision; see the httpauth package for why.
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.