Exemple #1
0
        async Task ClientCredentialsCertScenario()
        {
            X509Certificate2 certificate = GetCertificate();

            AzureActiveDirectoryTokenProvider.AuthenticationCallback authCallback = async(audience, authority, state) =>
            {
                IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create(ClientId)
                                                     .WithAuthority(authority)
                                                     .WithCertificate(certificate)
                                                     .Build();

                var serviceBusAudience = new Uri("https://servicebus.azure.net");

                var authResult = await app.AcquireTokenForClient(new string[] { $"{serviceBusAudience}/.default" }).ExecuteAsync();

                return(authResult.AccessToken);
            };

            QueueClient qc = QueueClient.CreateWithAzureActiveDirectory(
                new Uri($"sb://{ServiceBusNamespace}/"),
                QueueName,
                authCallback,
                $"https://login.windows.net/{TenantId}");

            await SendReceiveAsync(qc);
        }
Exemple #2
0
        async Task UserInteractiveLoginScenario()
        {
            AzureActiveDirectoryTokenProvider.AuthenticationCallback authCallback = async(audience, authority, state) =>
            {
                var app = PublicClientApplicationBuilder.Create(ClientId)
                          .WithRedirectUri(ConfigurationManager.AppSettings["redirectURI"])
                          .Build();

                var serviceBusAudience = new Uri("https://servicebus.azure.net");

                var authResult = await app.AcquireTokenInteractive(new string[] { $"{serviceBusAudience}/.default" }).ExecuteAsync();

                return(authResult.AccessToken);
            };

            QueueClient qc = QueueClient.CreateWithAzureActiveDirectory(
                new Uri($"sb://{ServiceBusNamespace}/"),
                QueueName,
                authCallback,
                $"https://login.windows.net/{TenantId}");

            await SendReceiveAsync(qc);
        }