use requested service (#1413)

This commit is contained in:
Asim Aslam 2020-03-25 20:59:37 +00:00 committed by GitHub
parent 8d0826a031
commit 6efc5556e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 8 deletions

View File

@ -46,7 +46,7 @@ func newService(opts ...Option) Service {
options.Server.Init( options.Server.Init(
server.WrapHandler(wrapper.HandlerStats(stats.DefaultStats)), server.WrapHandler(wrapper.HandlerStats(stats.DefaultStats)),
server.WrapHandler(wrapper.TraceHandler(trace.DefaultTracer)), server.WrapHandler(wrapper.TraceHandler(trace.DefaultTracer)),
server.WrapHandler(wrapper.AuthHandler(authFn, serviceName)), server.WrapHandler(wrapper.AuthHandler(authFn)),
) )
// set opts // set opts

View File

@ -152,7 +152,7 @@ func TraceHandler(t trace.Tracer) server.HandlerWrapper {
} }
// AuthHandler wraps a server handler to perform auth // AuthHandler wraps a server handler to perform auth
func AuthHandler(fn func() auth.Auth, srvName string) server.HandlerWrapper { func AuthHandler(fn func() auth.Auth) server.HandlerWrapper {
return func(h server.HandlerFunc) server.HandlerFunc { return func(h server.HandlerFunc) server.HandlerFunc {
return func(ctx context.Context, req server.Request, rsp interface{}) error { return func(ctx context.Context, req server.Request, rsp interface{}) error {
// get the auth.Auth interface // get the auth.Auth interface
@ -187,11 +187,11 @@ func AuthHandler(fn func() auth.Auth, srvName string) server.HandlerWrapper {
} }
// Verify the caller has access to the resource // Verify the caller has access to the resource
err = a.Verify(account, &auth.Resource{Type: "service", Name: srvName, Endpoint: req.Endpoint()}) err = a.Verify(account, &auth.Resource{Type: "service", Name: req.Service(), Endpoint: req.Endpoint()})
if err != nil && len(account.ID) > 0 { if err != nil && len(account.ID) > 0 {
return errors.Forbidden("go.micro.auth", "Forbidden call made to %v:%v by %v", srvName, req.Endpoint(), account.ID) return errors.Forbidden("go.micro.auth", "Forbidden call made to %v:%v by %v", req.Service(), req.Endpoint(), account.ID)
} else if err != nil { } else if err != nil {
return errors.Unauthorized("go.micro.auth", "Unauthorised call made to %v:%v", srvName, req.Endpoint()) return errors.Unauthorized("go.micro.auth", "Unauthorised call made to %v:%v", req.Service(), req.Endpoint())
} }
// There is an account, set it in the context // There is an account, set it in the context