From e396b8dbeac9dbe3a426cf13f4e7d1ce9a558e2a Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 17 Aug 2015 15:02:23 -0700 Subject: [PATCH] add method info to auth interceptor --- src/csharp/Grpc.Auth/AuthInterceptors.cs | 4 +-- src/csharp/Grpc.Core/ClientBase.cs | 4 +-- src/csharp/Grpc.Core/Method.cs | 29 ++++++++++++++++++- .../Grpc.IntegrationTesting/InteropClient.cs | 2 +- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/csharp/Grpc.Auth/AuthInterceptors.cs b/src/csharp/Grpc.Auth/AuthInterceptors.cs index 5a5ca7edc71..61338f7f0e2 100644 --- a/src/csharp/Grpc.Auth/AuthInterceptors.cs +++ b/src/csharp/Grpc.Auth/AuthInterceptors.cs @@ -54,7 +54,7 @@ namespace Grpc.Auth /// public static HeaderInterceptor FromCredential(ITokenAccess credential) { - return new HeaderInterceptor((authUri, metadata) => + return new HeaderInterceptor((method, authUri, metadata) => { // TODO(jtattermusch): Rethink synchronous wait to obtain the result. var accessToken = credential.GetAccessTokenForRequestAsync(authUri, CancellationToken.None) @@ -70,7 +70,7 @@ namespace Grpc.Auth public static HeaderInterceptor FromAccessToken(string accessToken) { Preconditions.CheckNotNull(accessToken); - return new HeaderInterceptor((authUri, metadata) => + return new HeaderInterceptor((method, authUri, metadata) => { metadata.Add(CreateBearerTokenHeader(accessToken)); }); diff --git a/src/csharp/Grpc.Core/ClientBase.cs b/src/csharp/Grpc.Core/ClientBase.cs index 751d2d260fe..7bc100ca603 100644 --- a/src/csharp/Grpc.Core/ClientBase.cs +++ b/src/csharp/Grpc.Core/ClientBase.cs @@ -40,7 +40,7 @@ namespace Grpc.Core /// /// Interceptor for call headers. /// - public delegate void HeaderInterceptor(string authUri, Metadata metadata); + public delegate void HeaderInterceptor(IMethod method, string authUri, Metadata metadata); /// /// Base class for client-side stubs. @@ -107,7 +107,7 @@ namespace Grpc.Core options = options.WithHeaders(new Metadata()); } var authUri = authUriBase != null ? authUriBase + method.ServiceName : null; - interceptor(authUri, options.Headers); + interceptor(method, authUri, options.Headers); } return new CallInvocationDetails(channel, method, Host, options); } diff --git a/src/csharp/Grpc.Core/Method.cs b/src/csharp/Grpc.Core/Method.cs index 4c208b4a263..4c53285893e 100644 --- a/src/csharp/Grpc.Core/Method.cs +++ b/src/csharp/Grpc.Core/Method.cs @@ -54,10 +54,37 @@ namespace Grpc.Core DuplexStreaming } + /// + /// A non-generic representation of a remote method. + /// + public interface IMethod + { + /// + /// Gets the type of the method. + /// + MethodType Type { get; } + + /// + /// Gets the name of the service to which this method belongs. + /// + string ServiceName { get; } + + /// + /// Gets the unqualified name of the method. + /// + string Name { get; } + + /// + /// Gets the fully qualified name of the method. On the server side, methods are dispatched + /// based on this name. + /// + string FullName { get; } + } + /// /// A description of a remote method. /// - public class Method + public class Method : IMethod { readonly MethodType type; readonly string serviceName; diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs index 1047f2efc10..f4b0a1028f9 100644 --- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs +++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs @@ -409,7 +409,7 @@ namespace Grpc.IntegrationTesting .Build(); var headers = new Metadata(); - headerInterceptor("", headers); + headerInterceptor(null, "", headers); var response = client.UnaryCall(request, headers: headers); Assert.AreEqual(AuthScopeResponse, response.OauthScope);