diff options
Diffstat (limited to 'src/csharp/Grpc.Core/ServerCallContext.cs')
-rw-r--r-- | src/csharp/Grpc.Core/ServerCallContext.cs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/csharp/Grpc.Core/ServerCallContext.cs b/src/csharp/Grpc.Core/ServerCallContext.cs index 8f28fbc045..c8950b7677 100644 --- a/src/csharp/Grpc.Core/ServerCallContext.cs +++ b/src/csharp/Grpc.Core/ServerCallContext.cs @@ -32,7 +32,6 @@ #endregion using System; -using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -56,6 +55,7 @@ namespace Grpc.Core private Status status = Status.DefaultSuccess; private Func<Metadata, Task> writeHeadersFunc; private IHasWriteOptions writeOptionsHolder; + private Lazy<AuthContext> authContext; internal ServerCallContext(CallSafeHandle callHandle, string method, string host, DateTime deadline, Metadata requestHeaders, CancellationToken cancellationToken, Func<Metadata, Task> writeHeadersFunc, IHasWriteOptions writeOptionsHolder) @@ -68,6 +68,7 @@ namespace Grpc.Core this.cancellationToken = cancellationToken; this.writeHeadersFunc = writeHeadersFunc; this.writeOptionsHolder = writeOptionsHolder; + this.authContext = new Lazy<AuthContext>(GetAuthContextEager); } /// <summary> @@ -187,6 +188,26 @@ namespace Grpc.Core writeOptionsHolder.WriteOptions = value; } } + + /// <summary> + /// Gets the <c>AuthContext</c> associated with this call. + /// Note: Access to AuthContext is an experimental API that can change without any prior notice. + /// </summary> + public AuthContext AuthContext + { + get + { + return authContext.Value; + } + } + + private AuthContext GetAuthContextEager() + { + using (var authContextNative = callHandle.GetAuthContext()) + { + return authContextNative.ToAuthContext(); + } + } } /// <summary> |