AsyncAuthInterceptor.cs 2.2 KB

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