From 18729a05e59c93eb258eb0a72cf2af4c22b28041 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 8 Oct 2015 18:40:00 -0700 Subject: Polishing of C# auth API --- src/csharp/Grpc.Core/CallCredentials.cs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src/csharp/Grpc.Core/CallCredentials.cs') 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 @@ -40,6 +40,14 @@ using Grpc.Core.Utils; namespace Grpc.Core { + /// + /// Asynchronous authentication interceptor for . + /// + /// URL of a service to which current remote call needs to authenticate + /// Metadata to populate with entries that will be added to outgoing call's headers. + /// + public delegate Task AsyncAuthInterceptor(string authUri, Metadata metadata); + /// /// Client-side call credentials. Provide authorization with per-call granularity. /// @@ -56,6 +64,16 @@ namespace Grpc.Core return new CompositeCallCredentials(credentials); } + /// + /// Creates a new instance of CallCredentials class from an + /// interceptor that can attach metadata to outgoing calls. + /// + /// authentication interceptor + public static CallCredentials FromInterceptor(AsyncAuthInterceptor interceptor) + { + return new MetadataCredentials(interceptor); + } + /// /// Creates native object for the credentials. /// @@ -63,19 +81,11 @@ namespace Grpc.Core internal abstract CredentialsSafeHandle ToNativeCredentials(); } - /// - /// Asynchronous authentication interceptor for . - /// - /// URL of a service to which current remote call needs to authenticate - /// Metadata to populate with entries that will be added to outgoing call's headers. - /// - public delegate Task AsyncAuthInterceptor(string authUri, Metadata metadata); - /// /// Client-side credentials that delegate metadata based auth to an interceptor. /// The interceptor is automatically invoked for each remote call that uses MetadataCredentials. /// - public class MetadataCredentials : CallCredentials + internal sealed class MetadataCredentials : CallCredentials { readonly AsyncAuthInterceptor interceptor; @@ -85,7 +95,7 @@ namespace Grpc.Core /// authentication interceptor public MetadataCredentials(AsyncAuthInterceptor interceptor) { - this.interceptor = interceptor; + this.interceptor = Preconditions.CheckNotNull(interceptor); } internal override CredentialsSafeHandle ToNativeCredentials() -- cgit v1.2.3