Imported Upstream version 1.21.0
[platform/upstream/grpc.git] / src / csharp / Grpc.Core.Api / AsyncAuthInterceptor.cs
1 #region Copyright notice and license
2
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16
17 #endregion
18
19 using System;
20 using System.Collections.Generic;
21 using System.Threading.Tasks;
22
23 using Grpc.Core.Internal;
24 using Grpc.Core.Utils;
25
26 namespace Grpc.Core
27 {
28     /// <summary>
29     /// Asynchronous authentication interceptor for <see cref="CallCredentials"/>.
30     /// </summary>
31     /// <param name="context">The interceptor context.</param>
32     /// <param name="metadata">Metadata to populate with entries that will be added to outgoing call's headers.</param>
33     /// <returns></returns>
34     public delegate Task AsyncAuthInterceptor(AuthInterceptorContext context, Metadata metadata);
35
36     /// <summary>
37     /// Context for an RPC being intercepted by <see cref="AsyncAuthInterceptor"/>.
38     /// </summary>
39     public class AuthInterceptorContext
40     {
41         readonly string serviceUrl;
42         readonly string methodName;
43
44         /// <summary>
45         /// Initializes a new instance of <c>AuthInterceptorContext</c>.
46         /// </summary>
47         public AuthInterceptorContext(string serviceUrl, string methodName)
48         {
49             this.serviceUrl = GrpcPreconditions.CheckNotNull(serviceUrl);
50             this.methodName = GrpcPreconditions.CheckNotNull(methodName);
51         }
52
53         /// <summary>
54         /// The fully qualified service URL for the RPC being called.
55         /// </summary>
56         public string ServiceUrl
57         {
58             get { return serviceUrl; }
59         }
60
61         /// <summary>
62         /// The method name of the RPC being called.
63         /// </summary>
64         public string MethodName
65         {
66             get { return methodName; }
67         }
68     }
69 }