From 042bc10bf3277bf1089b196779528da5df780aa6 Mon Sep 17 00:00:00 2001 From: Eyal Date: Thu, 24 May 2018 09:48:57 +0300 Subject: [PATCH] fix makefile --- Makefile | 6 +++--- example/restapi/configure_swagger_petstore.go | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 7b9db40..5ad65a0 100644 --- a/Makefile +++ b/Makefile @@ -19,9 +19,9 @@ test: go test ./... example: build clean - cd example && \ - $(swagger) generate server && \ - $(swagger) generate client && \ + cd example ; \ + $(swagger) generate server ; \ + $(swagger) generate client ; \ go generate ./... clean: diff --git a/example/restapi/configure_swagger_petstore.go b/example/restapi/configure_swagger_petstore.go index 41ceaf7..282f163 100644 --- a/example/restapi/configure_swagger_petstore.go +++ b/example/restapi/configure_swagger_petstore.go @@ -52,10 +52,16 @@ type Config struct { // The middleware executes after routing but before authentication, binding and validation InnerMiddleware func(http.Handler) http.Handler + // Authorizer is used to authorize a request after the Auth function was called using the "Auth*" functions + // and the principal was stored in the context using the "StoreAuth" function. Authorizer func(*http.Request) error - StoreAuth func(context.Context, interface{}) context.Context - // Applies when the "Cookie" header is set + // StoreAuth is used to store a principal in the request context. + // After storing the principal in the context, one can get it from the context in the business logic + // using a dedicated typed function. + StoreAuth func(context.Context, interface{}) context.Context + + // AuthKey Applies when the "Cookie" header is set AuthKey func(token string) (interface{}, error) } @@ -168,6 +174,11 @@ type authorizer struct { func (a *authorizer) Authorize(req *http.Request, principal interface{}) error { ctx := req.Context() - ctx = a.store(ctx, principal) + if a.store != nil { + ctx = a.store(ctx, principal) + } + if a.authorize == nil { + return nil + } return a.authorize(req.WithContext(ctx)) }