Documentation ¶
Index ¶
- Variables
- func CheckAuthInContextMiddleware(ctx context.Context, rw http.ResponseWriter, req *http.Request) (context.Context, http.ResponseWriter, error)
- func DummyUserPassAuthBuilder(userRepo UserRepository) chain.MiddlewareBuilder
- func RetrieveAuthFromContext() error
- func SecurityChainExample()
- func SecurityChainExampleFailAuth()
- func SetAuthInContext() error
- type DBUser
- type UserRepository
Constants ¶
This section is empty.
Variables ¶
var NoAuthenticationPresent = goa.NewErrorClass("authentication_required", 401)
NoAuthenticationPresent is a custom error for the auth middleware generated when there is no authentication created
Functions ¶
func CheckAuthInContextMiddleware ¶
func CheckAuthInContextMiddleware(ctx context.Context, rw http.ResponseWriter, req *http.Request) (context.Context, http.ResponseWriter, error)
CheckAuthInContextMiddleware is a chain.SecurityChainMiddleware that performs a check for the Auth object in the context. This middleware ilustrates the usage of the auth package (auth.HasAuth function). Note that the middleware returns an Goa error (custom defined for the purposes of the auth chain). Later on, when the chain will return control over to Goa, this error will be serialized and retuned back to the client. Returnning an error would cause the chain to break after this middleware and would return to Goa immediately. Since the chain itself would return an error, this would also break the Goa chain and the actual microservice action will not be called.
func DummyUserPassAuthBuilder ¶
func DummyUserPassAuthBuilder(userRepo UserRepository) chain.MiddlewareBuilder
DummyUserPassAuthBuilder returns a chain.MiddlewareBuilder factory function. This illustrates passing a custom data to a chain.MiddlewareBuilder. In this case we're sending a UserRepository that is used by the middleware to check the username+password, but in real-world scenario we can pass a secret key or a security store path to the middleware.
func RetrieveAuthFromContext ¶
func RetrieveAuthFromContext() error
RetrieveAuthFromContext first stores an Auth object in context, then retrieves it via auth.GetAuth
func SecurityChainExample ¶
func SecurityChainExample()
SecurityChainExample illustrates setting up a security chain with 2 middlewares: 1. the "dummy" middleware that should create the Auth 2. Middleware that checks for Auth object in the context.
func SecurityChainExampleFailAuth ¶
func SecurityChainExampleFailAuth()
SecurityChainExampleFailAuth illustrates setting up a security chain same as SecurityChainExample, but the request contains wrong authentication and the chain returns an error.
func SetAuthInContext ¶
func SetAuthInContext() error
SetAuthInContext sets an auth.Auth object in context and checks for it
Types ¶
type UserRepository ¶
UserRepository is an in-memory user data store. It is a map holding the users. The key is composed of the username and password: <username>:<password>.
func (UserRepository) FindByUsernameAndPassword ¶
func (repo UserRepository) FindByUsernameAndPassword(username string, pass string) *DBUser
FindByUsernameAndPassword looks up a user by its username and password in the UserRepository.