Skip to content
Snippets Groups Projects
Commit e396b8db authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

add method info to auth interceptor

parent e7178527
No related branches found
No related tags found
No related merge requests found
...@@ -54,7 +54,7 @@ namespace Grpc.Auth ...@@ -54,7 +54,7 @@ namespace Grpc.Auth
/// </summary> /// </summary>
public static HeaderInterceptor FromCredential(ITokenAccess credential) 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. // TODO(jtattermusch): Rethink synchronous wait to obtain the result.
var accessToken = credential.GetAccessTokenForRequestAsync(authUri, CancellationToken.None) var accessToken = credential.GetAccessTokenForRequestAsync(authUri, CancellationToken.None)
...@@ -70,7 +70,7 @@ namespace Grpc.Auth ...@@ -70,7 +70,7 @@ namespace Grpc.Auth
public static HeaderInterceptor FromAccessToken(string accessToken) public static HeaderInterceptor FromAccessToken(string accessToken)
{ {
Preconditions.CheckNotNull(accessToken); Preconditions.CheckNotNull(accessToken);
return new HeaderInterceptor((authUri, metadata) => return new HeaderInterceptor((method, authUri, metadata) =>
{ {
metadata.Add(CreateBearerTokenHeader(accessToken)); metadata.Add(CreateBearerTokenHeader(accessToken));
}); });
......
...@@ -40,7 +40,7 @@ namespace Grpc.Core ...@@ -40,7 +40,7 @@ namespace Grpc.Core
/// <summary> /// <summary>
/// Interceptor for call headers. /// Interceptor for call headers.
/// </summary> /// </summary>
public delegate void HeaderInterceptor(string authUri, Metadata metadata); public delegate void HeaderInterceptor(IMethod method, string authUri, Metadata metadata);
/// <summary> /// <summary>
/// Base class for client-side stubs. /// Base class for client-side stubs.
...@@ -107,7 +107,7 @@ namespace Grpc.Core ...@@ -107,7 +107,7 @@ namespace Grpc.Core
options = options.WithHeaders(new Metadata()); options = options.WithHeaders(new Metadata());
} }
var authUri = authUriBase != null ? authUriBase + method.ServiceName : null; 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); return new CallInvocationDetails<TRequest, TResponse>(channel, method, Host, options);
} }
......
...@@ -54,10 +54,37 @@ namespace Grpc.Core ...@@ -54,10 +54,37 @@ namespace Grpc.Core
DuplexStreaming 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> /// <summary>
/// A description of a remote method. /// A description of a remote method.
/// </summary> /// </summary>
public class Method<TRequest, TResponse> public class Method<TRequest, TResponse> : IMethod
{ {
readonly MethodType type; readonly MethodType type;
readonly string serviceName; readonly string serviceName;
......
...@@ -409,7 +409,7 @@ namespace Grpc.IntegrationTesting ...@@ -409,7 +409,7 @@ namespace Grpc.IntegrationTesting
.Build(); .Build();
var headers = new Metadata(); var headers = new Metadata();
headerInterceptor("", headers); headerInterceptor(null, "", headers);
var response = client.UnaryCall(request, headers: headers); var response = client.UnaryCall(request, headers: headers);
Assert.AreEqual(AuthScopeResponse, response.OauthScope); Assert.AreEqual(AuthScopeResponse, response.OauthScope);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment