From e396b8dbeac9dbe3a426cf13f4e7d1ce9a558e2a Mon Sep 17 00:00:00 2001
From: Jan Tattermusch <jtattermusch@google.com>
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 5a5ca7edc7..61338f7f0e 100644
--- a/src/csharp/Grpc.Auth/AuthInterceptors.cs
+++ b/src/csharp/Grpc.Auth/AuthInterceptors.cs
@@ -54,7 +54,7 @@ namespace Grpc.Auth
         /// </summary>
         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 751d2d260f..7bc100ca60 100644
--- a/src/csharp/Grpc.Core/ClientBase.cs
+++ b/src/csharp/Grpc.Core/ClientBase.cs
@@ -40,7 +40,7 @@ namespace Grpc.Core
     /// <summary>
     /// Interceptor for call headers.
     /// </summary>
-    public delegate void HeaderInterceptor(string authUri, Metadata metadata);
+    public delegate void HeaderInterceptor(IMethod method, string authUri, Metadata metadata);
 
     /// <summary>
     /// 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<TRequest, TResponse>(channel, method, Host, options);
         }
diff --git a/src/csharp/Grpc.Core/Method.cs b/src/csharp/Grpc.Core/Method.cs
index 4c208b4a26..4c53285893 100644
--- a/src/csharp/Grpc.Core/Method.cs
+++ b/src/csharp/Grpc.Core/Method.cs
@@ -54,10 +54,37 @@ namespace Grpc.Core
         DuplexStreaming
     }
 
+    /// <summary>
+    /// A non-generic representation of a remote method.
+    /// </summary>
+    public interface IMethod
+    {
+        /// <summary>
+        /// Gets the type of the method.
+        /// </summary>
+        MethodType Type { get; }
+
+        /// <summary>
+        /// Gets the name of the service to which this method belongs.
+        /// </summary>
+        string ServiceName { get; }
+
+        /// <summary>
+        /// Gets the unqualified name of the method.
+        /// </summary>
+        string Name { get; }
+
+        /// <summary>
+        /// Gets the fully qualified name of the method. On the server side, methods are dispatched
+        /// based on this name.
+        /// </summary>
+        string FullName { get; }
+    }
+
     /// <summary>
     /// A description of a remote method.
     /// </summary>
-    public class Method<TRequest, TResponse>
+    public class Method<TRequest, TResponse> : IMethod
     {
         readonly MethodType type;
         readonly string serviceName;
diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs
index 1047f2efc1..f4b0a1028f 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);
-- 
GitLab