< Summary

Class:Azure.Messaging.EventHubs.Authorization.EventHubTokenCredential
Assembly:Azure.Messaging.EventHubs.Processor
File(s):C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs.Shared\src\Authorization\EventHubTokenCredential.cs
Covered lines:0
Uncovered lines:17
Coverable lines:17
Total lines:101
Line coverage:0% (0 of 17)
Covered branches:0
Total branches:6
Branch coverage:0% (0 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Resource()-0%100%
get_IsSharedAccessSignatureCredential()-0%100%
get_Credential()-0%100%
.ctor(...)-0%0%
GetToken(...)-0%100%
GetTokenAsync(...)-0%100%
GetTokenUsingDefaultScopeAsync(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\eventhub\Azure.Messaging.EventHubs.Shared\src\Authorization\EventHubTokenCredential.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Threading;
 5using System.Threading.Tasks;
 6using Azure.Core;
 7
 8namespace Azure.Messaging.EventHubs.Authorization
 9{
 10    /// <summary>
 11    ///   Provides a generic token-based credential for a given Event Hub instance.
 12    /// </summary>
 13    ///
 14    /// <seealso cref="Azure.Core.TokenCredential" />
 15    ///
 16    internal class EventHubTokenCredential : TokenCredential
 17    {
 18        /// <summary>The default scope used for token authentication with EventHubs.</summary>
 19        private const string DefaultScope = "https://eventhubs.azure.net/.default";
 20
 21        /// <summary>
 22        ///   The Event Hubs resource to which the token is intended to serve as authorization.
 23        /// </summary>
 24        ///
 025        public string Resource { get; }
 26
 27        /// <summary>
 28        ///   Indicates whether the credential is based on an Event Hubs
 29        ///   shared access signature.
 30        /// </summary>
 31        ///
 32        /// <value><c>true</c> if the credential should be considered a SAS credential; otherwise, <c>false</c>.</value>
 33        ///
 034        public bool IsSharedAccessSignatureCredential { get; }
 35
 36        /// <summary>
 37        ///   The <see cref="TokenCredential" /> that forms the basis of this security token.
 38        /// </summary>
 39        ///
 040        private TokenCredential Credential { get; }
 41
 42        /// <summary>
 43        ///   Initializes a new instance of the <see cref="EventHubTokenCredential"/> class.
 44        /// </summary>
 45        ///
 46        /// <param name="tokenCredential">The <see cref="TokenCredential" /> on which to base the token.</param>
 47        /// <param name="eventHubResource">The Event Hubs resource to which the token is intended to serve as authorizat
 48        ///
 049        public EventHubTokenCredential(TokenCredential tokenCredential,
 050                                       string eventHubResource)
 51        {
 052            Argument.AssertNotNull(tokenCredential, nameof(tokenCredential));
 053            Argument.AssertNotNullOrEmpty(eventHubResource, nameof(eventHubResource));
 54
 055            Credential = tokenCredential;
 056            Resource = eventHubResource;
 57
 058            IsSharedAccessSignatureCredential =
 059                (tokenCredential is EventHubSharedKeyCredential)
 060                || (tokenCredential is SharedAccessSignatureCredential)
 061                || ((tokenCredential as EventHubTokenCredential)?.IsSharedAccessSignatureCredential == true);
 062        }
 63
 64        /// <summary>
 65        ///   Retrieves the token that represents the shared access signature credential, for
 66        ///   use in authorization against an Event Hub.
 67        /// </summary>
 68        ///
 69        /// <param name="requestContext">The details of the authentication request.</param>
 70        /// <param name="cancellationToken">The token used to request cancellation of the operation.</param>
 71        ///
 72        /// <returns>The token representing the shared access signature for this credential.</returns>
 73        ///
 74        public override AccessToken GetToken(TokenRequestContext requestContext,
 075                                             CancellationToken cancellationToken) => Credential.GetToken(requestContext,
 76
 77        /// <summary>
 78        ///   Retrieves the token that represents the shared access signature credential, for
 79        ///   use in authorization against an Event Hub.
 80        /// </summary>
 81        ///
 82        /// <param name="requestContext">The details of the authentication request.</param>
 83        /// <param name="cancellationToken">The token used to request cancellation of the operation.</param>
 84        ///
 85        /// <returns>The token representing the shared access signature for this credential.</returns>
 86        ///
 87        public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext,
 088                                                             CancellationToken cancellationToken) => Credential.GetToken
 89
 90        /// <summary>
 91        ///   Retrieves the token that represents the shared access signature credential, for
 92        ///   use in authorization against an Event Hub. It provides a default value for the Token Request Context.
 93        /// </summary>
 94        ///
 95        /// <param name="cancellationToken">The token used to request cancellation of the operation.</param>
 96        ///
 97        /// <returns>The token representing the shared access signature for this credential.</returns>
 98        ///
 099        public ValueTask<AccessToken> GetTokenUsingDefaultScopeAsync(CancellationToken cancellationToken) => GetTokenAsy
 100    }
 101}