Beispiel #1
0
        private static async Task <string> GetTokenByThumbprint(string adAppId, string thumbprint, string authority, string resource, CancellationToken cancellationToken)
        {
            var context         = new AuthenticationContext(authority, TokenCache.DefaultShared);
            var certificate     = CertificateExtensions.FindByThumbprint(thumbprint);
            var clientAssertion = new ClientAssertionCertificate(adAppId, certificate);

            var result = await context.AcquireTokenAsync(resource, clientAssertion).ConfigureAwait(false);

            if (result?.AccessToken == null)
            {
                throw new InvalidOperationException($"Unable to acquire token for resource {resource}. Authority: {authority}. ApplicationId: {adAppId}. Thumbprint: {thumbprint}");
            }

            return(result.AccessToken);
        }
Beispiel #2
0
 public static X509Certificate2 FindCertificateByThumbprint(this StoreLocation location, string thumbprint, StoreName name = StoreName.My)
 {
     return(CertificateExtensions.FindCertificateInternal(location, name, X509FindType.FindByThumbprint, thumbprint, false));
 }