diff options
Diffstat (limited to 'src/csharp/Grpc.Core')
-rw-r--r-- | src/csharp/Grpc.Core/CallCredentials.cs | 30 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/ChannelCredentials.cs | 33 |
2 files changed, 20 insertions, 43 deletions
diff --git a/src/csharp/Grpc.Core/CallCredentials.cs b/src/csharp/Grpc.Core/CallCredentials.cs index 809c9f412d..400a9825de 100644 --- a/src/csharp/Grpc.Core/CallCredentials.cs +++ b/src/csharp/Grpc.Core/CallCredentials.cs @@ -41,6 +41,14 @@ using Grpc.Core.Utils; namespace Grpc.Core { /// <summary> + /// Asynchronous authentication interceptor for <see cref="CallCredentials"/>. + /// </summary> + /// <param name="authUri">URL of a service to which current remote call needs to authenticate</param> + /// <param name="metadata">Metadata to populate with entries that will be added to outgoing call's headers.</param> + /// <returns></returns> + public delegate Task AsyncAuthInterceptor(string authUri, Metadata metadata); + + /// <summary> /// Client-side call credentials. Provide authorization with per-call granularity. /// </summary> public abstract class CallCredentials @@ -57,6 +65,16 @@ namespace Grpc.Core } /// <summary> + /// Creates a new instance of <c>CallCredentials</c> class from an + /// interceptor that can attach metadata to outgoing calls. + /// </summary> + /// <param name="interceptor">authentication interceptor</param> + public static CallCredentials FromInterceptor(AsyncAuthInterceptor interceptor) + { + return new MetadataCredentials(interceptor); + } + + /// <summary> /// Creates native object for the credentials. /// </summary> /// <returns>The native credentials.</returns> @@ -64,18 +82,10 @@ namespace Grpc.Core } /// <summary> - /// Asynchronous authentication interceptor for <see cref="MetadataCredentials"/>. - /// </summary> - /// <param name="authUri">URL of a service to which current remote call needs to authenticate</param> - /// <param name="metadata">Metadata to populate with entries that will be added to outgoing call's headers.</param> - /// <returns></returns> - public delegate Task AsyncAuthInterceptor(string authUri, Metadata metadata); - - /// <summary> /// Client-side credentials that delegate metadata based auth to an interceptor. /// The interceptor is automatically invoked for each remote call that uses <c>MetadataCredentials.</c> /// </summary> - public class MetadataCredentials : CallCredentials + internal sealed class MetadataCredentials : CallCredentials { readonly AsyncAuthInterceptor interceptor; @@ -85,7 +95,7 @@ namespace Grpc.Core /// <param name="interceptor">authentication interceptor</param> public MetadataCredentials(AsyncAuthInterceptor interceptor) { - this.interceptor = interceptor; + this.interceptor = Preconditions.CheckNotNull(interceptor); } internal override CredentialsSafeHandle ToNativeCredentials() diff --git a/src/csharp/Grpc.Core/ChannelCredentials.cs b/src/csharp/Grpc.Core/ChannelCredentials.cs index 599674e02b..9d2bcdabe8 100644 --- a/src/csharp/Grpc.Core/ChannelCredentials.cs +++ b/src/csharp/Grpc.Core/ChannelCredentials.cs @@ -72,17 +72,6 @@ namespace Grpc.Core } /// <summary> - /// Creates a new instance of <c>ChannelCredentials</c> by wrapping - /// an instance of <c>CallCredentials</c>. - /// </summary> - /// <param name="callCredentials">Call credentials.</param> - /// <returns>The <c>ChannelCredentials</c> wrapping given call credentials.</returns> - public static ChannelCredentials Create(CallCredentials callCredentials) - { - return new WrappedCallCredentials(callCredentials); - } - - /// <summary> /// Creates native object for the credentials. May return null if insecure channel /// should be created. /// </summary> @@ -213,26 +202,4 @@ namespace Grpc.Core } } } - - /// <summary> - /// Credentials wrapping <see cref="CallCredentials"/> as <see cref="ChannelCredentials"/>. - /// </summary> - internal sealed class WrappedCallCredentials : ChannelCredentials - { - readonly CallCredentials callCredentials; - - /// <summary> - /// Wraps instance of <c>CallCredentials</c> as <c>ChannelCredentials</c>. - /// </summary> - /// <param name="callCredentials">credentials to wrap</param> - public WrappedCallCredentials(CallCredentials callCredentials) - { - this.callCredentials = Preconditions.CheckNotNull(callCredentials); - } - - internal override CredentialsSafeHandle ToNativeCredentials() - { - return callCredentials.ToNativeCredentials(); - } - } } |