add method info to auth interceptor

pull/2964/head
Jan Tattermusch 10 years ago
parent e7178527ff
commit e396b8dbea
  1. 4
      src/csharp/Grpc.Auth/AuthInterceptors.cs
  2. 4
      src/csharp/Grpc.Core/ClientBase.cs
  3. 29
      src/csharp/Grpc.Core/Method.cs
  4. 2
      src/csharp/Grpc.IntegrationTesting/InteropClient.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));
});

@ -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);
}

@ -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;

@ -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);

Loading…
Cancel
Save