aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Auth
diff options
context:
space:
mode:
authorGravatar Julien Boeuf <jboeuf@google.com>2015-10-17 22:14:29 -0700
committerGravatar Julien Boeuf <jboeuf@google.com>2015-10-17 22:14:29 -0700
commit3bb61d8917a506c8bbeadfa651f59ec37c74849f (patch)
treea5b5ecd11d25d354de1b774906fed642d4cb562f /src/csharp/Grpc.Auth
parent18a12c4e9b1b86a9b29302ed8aac9dc9e5cecfe3 (diff)
parent627f98454cf120d1b91205b381dcbc1c9c2cccfb (diff)
Merge branch 'master' of https://github.com/grpc/grpc into core_creds_api_change
Diffstat (limited to 'src/csharp/Grpc.Auth')
-rw-r--r--src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs (renamed from src/csharp/Grpc.Auth/AuthInterceptors.cs)6
-rw-r--r--src/csharp/Grpc.Auth/GoogleGrpcCredentials.cs (renamed from src/csharp/Grpc.Auth/GrpcCredentials.cs)57
-rw-r--r--src/csharp/Grpc.Auth/Grpc.Auth.csproj4
3 files changed, 35 insertions, 32 deletions
diff --git a/src/csharp/Grpc.Auth/AuthInterceptors.cs b/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs
index fa92566775..1c14c5bb5b 100644
--- a/src/csharp/Grpc.Auth/AuthInterceptors.cs
+++ b/src/csharp/Grpc.Auth/GoogleAuthInterceptors.cs
@@ -41,10 +41,10 @@ using Grpc.Core.Utils;
namespace Grpc.Auth
{
/// <summary>
- /// Factory methods to create authorization interceptors.
- /// <seealso cref="GrpcCredentials"/>
+ /// Factory methods to create authorization interceptors for Google credentials.
+ /// <seealso cref="GoogleGrpcCredentials"/>
/// </summary>
- public static class AuthInterceptors
+ public static class GoogleAuthInterceptors
{
private const string AuthorizationHeader = "Authorization";
private const string Schema = "Bearer";
diff --git a/src/csharp/Grpc.Auth/GrpcCredentials.cs b/src/csharp/Grpc.Auth/GoogleGrpcCredentials.cs
index d8b10804c6..a1e7db13bd 100644
--- a/src/csharp/Grpc.Auth/GrpcCredentials.cs
+++ b/src/csharp/Grpc.Auth/GoogleGrpcCredentials.cs
@@ -33,6 +33,7 @@
using System;
using System.Threading;
+using System.Threading.Tasks;
using Google.Apis.Auth.OAuth2;
using Grpc.Core;
@@ -41,53 +42,55 @@ using Grpc.Core.Utils;
namespace Grpc.Auth
{
/// <summary>
- /// Factory methods to create instances of <see cref="ChannelCredentials"/> and <see cref="CallCredentials"/> classes.
+ /// Factory/extension methods to create instances of <see cref="ChannelCredentials"/> and <see cref="CallCredentials"/> classes
+ /// based on credential objects originating from Google auth library.
/// </summary>
- public static class GrpcCredentials
+ public static class GoogleGrpcCredentials
{
/// <summary>
- /// Creates a <see cref="MetadataCredentials"/> instance that will obtain access tokens
- /// from any credential that implements <c>ITokenAccess</c>. (e.g. <c>GoogleCredential</c>).
+ /// Retrieves an instance of Google's Application Default Credentials using
+ /// <c>GoogleCredential.GetApplicationDefaultAsync()</c> and converts them
+ /// into a gRPC <see cref="ChannelCredentials"/> that use the default SSL credentials.
/// </summary>
- /// <param name="credential">The credential to use to obtain access tokens.</param>
- /// <returns>The <c>MetadataCredentials</c> instance.</returns>
- public static MetadataCredentials Create(ITokenAccess credential)
+ /// <returns>The <c>ChannelCredentials</c> instance.</returns>
+ public static async Task<ChannelCredentials> GetApplicationDefaultAsync()
{
- return new MetadataCredentials(AuthInterceptors.FromCredential(credential));
+ var googleCredential = await GoogleCredential.GetApplicationDefaultAsync().ConfigureAwait(false);
+ return googleCredential.ToChannelCredentials();
}
/// <summary>
- /// Convenience method to create a <see cref="ChannelCredentials"/> instance from
- /// <c>ITokenAccess</c> credential and <c>SslCredentials</c> instance.
+ /// Creates an instance of <see cref="CallCredentials"/> that will use given access token to authenticate
+ /// with a gRPC service.
/// </summary>
- /// <param name="credential">The credential to use to obtain access tokens.</param>
- /// <param name="sslCredentials">The <c>SslCredentials</c> instance.</param>
- /// <returns>The channel credentials for access token based auth over a secure channel.</returns>
- public static ChannelCredentials Create(ITokenAccess credential, SslCredentials sslCredentials)
+ /// <param name="accessToken">OAuth2 access token.</param>
+ /// /// <returns>The <c>MetadataCredentials</c> instance.</returns>
+ public static CallCredentials FromAccessToken(string accessToken)
{
- return ChannelCredentials.Create(sslCredentials, Create(credential));
+ return CallCredentials.FromInterceptor(GoogleAuthInterceptors.FromAccessToken(accessToken));
}
/// <summary>
- /// Creates an instance of <see cref="MetadataCredentials"/> that will use given access token to authenticate
- /// with a gRPC service.
+ /// Converts a <c>ITokenAccess</c> (e.g. <c>GoogleCredential</c>) object
+ /// into a gRPC <see cref="CallCredentials"/> object.
/// </summary>
- /// <param name="accessToken">OAuth2 access token.</param>
- /// /// <returns>The <c>MetadataCredentials</c> instance.</returns>
- public static MetadataCredentials FromAccessToken(string accessToken)
+ /// <param name="credential">The credential to use to obtain access tokens.</param>
+ /// <returns>The <c>CallCredentials</c> instance.</returns>
+ public static CallCredentials ToCallCredentials(this ITokenAccess credential)
{
- return new MetadataCredentials(AuthInterceptors.FromAccessToken(accessToken));
+ return CallCredentials.FromInterceptor(GoogleAuthInterceptors.FromCredential(credential));
}
/// <summary>
- /// Converts a <c>ITokenAccess</c> object into a <see cref="MetadataCredentials"/> object supported
- /// by gRPC.
+ /// Converts a <c>ITokenAccess</c> (e.g. <c>GoogleCredential</c>) object
+ /// into a gRPC <see cref="ChannelCredentials"/> object.
+ /// Default SSL credentials are used.
/// </summary>
- /// <param name="credential"></param>
- /// <returns></returns>
- public static MetadataCredentials ToGrpcCredentials(this ITokenAccess credential)
+ /// <param name="googleCredential">The credential to use to obtain access tokens.</param>
+ /// <returns>>The <c>ChannelCredentials</c> instance.</returns>
+ public static ChannelCredentials ToChannelCredentials(this ITokenAccess googleCredential)
{
- return GrpcCredentials.Create(credential);
+ return ChannelCredentials.Create(new SslCredentials(), googleCredential.ToCallCredentials());
}
}
}
diff --git a/src/csharp/Grpc.Auth/Grpc.Auth.csproj b/src/csharp/Grpc.Auth/Grpc.Auth.csproj
index 80ab07d2ae..55bde6e194 100644
--- a/src/csharp/Grpc.Auth/Grpc.Auth.csproj
+++ b/src/csharp/Grpc.Auth/Grpc.Auth.csproj
@@ -78,9 +78,9 @@
<Compile Include="..\Grpc.Core\Version.cs">
<Link>Version.cs</Link>
</Compile>
- <Compile Include="GrpcCredentials.cs" />
+ <Compile Include="GoogleGrpcCredentials.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="AuthInterceptors.cs" />
+ <Compile Include="GoogleAuthInterceptors.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>