Documentation ¶
Overview ¶
Package middle contains middleware for use with the jelly server framework.
Index ¶
- func GetLoggedInUser(req *http.Request) (user jelly.AuthUser, loggedIn bool)
- type Provider
- func (p Provider) DontPanic(resp jelly.ResponseGenerator) jelly.Middleware
- func (p Provider) OptionalAuth(resp jelly.ResponseGenerator, authenticators ...string) jelly.Middleware
- func (p *Provider) RegisterAuthenticator(name string, authen jelly.Authenticator) error
- func (p *Provider) RegisterMainAuthenticator(name string) error
- func (p Provider) RequiredAuth(resp jelly.ResponseGenerator, authenticators ...string) jelly.Middleware
- func (p *Provider) SelectAuthenticator(from ...string) jelly.Authenticator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Provider ¶
type Provider struct { DisableDefaults bool // contains filtered or unexported fields }
Provider is used to create middleware in a jelly framework project. Generally for callers, it will be accessed via delegated methods on an instance of jelly.Environment.
func (Provider) DontPanic ¶
func (p Provider) DontPanic(resp jelly.ResponseGenerator) jelly.Middleware
DontPanic returns a Middleware that performs a panic check as it exits. If the function is panicking, it will write out an HTTP response with a generic message to the client and add it to the log.
func (Provider) OptionalAuth ¶
func (p Provider) OptionalAuth(resp jelly.ResponseGenerator, authenticators ...string) jelly.Middleware
OptionalAuth returns middleware that allows auth be used to retrieved the logged-in user. The authenticators, if provided, must give the names of preferred providers that were registered as an jelly.Authenticator with this package, in priority order. If none of the given authenticators exist, this function panics. If no authenticator is specified, the one set as main for the project is used.
func (*Provider) RegisterAuthenticator ¶
func (p *Provider) RegisterAuthenticator(name string, authen jelly.Authenticator) error
func (*Provider) RegisterMainAuthenticator ¶
func (Provider) RequiredAuth ¶
func (p Provider) RequiredAuth(resp jelly.ResponseGenerator, authenticators ...string) jelly.Middleware
RequiredAuth returns middleware that requires that auth be used. The authenticators, if provided, must give the names of preferred providers that were registered as an jelly.Authenticator with this package, in priority order. If none of the given authenticators exist, this function panics. If no authenticator is specified, the one set as main for the project is used.
func (*Provider) SelectAuthenticator ¶
func (p *Provider) SelectAuthenticator(from ...string) jelly.Authenticator
SelectAuthenticator retrieves and selects the first authenticator that matches one of the names in from. If no names are provided in from, the main auth for the project is returned. If from is not empty, at least one name listed in it must exist, or this function will panic.