1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-24 22:26:54 +02:00

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
3 changed files with 8 additions and 8 deletions

View File

@ -152,7 +152,7 @@ func TraceHandler(t trace.Tracer) server.HandlerWrapper {
}
// 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(ctx context.Context, req server.Request, rsp interface{}) error {
// 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
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 {
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 {
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