public async Task Authenticate()

in src/Common/Common.Authentication/ServicePrincipalAuthenticationFactory.cs [60:96]


        public async Task<IAccessToken> Authenticate(string clientId, string thumbprint, IPowerBIEnvironment environment, IPowerBILogger logger, IPowerBISettings settings)
        {
            var certificate = FindCertificate(thumbprint); 
            IEnumerable<string> scopes = new[] { $"{environment.AzureADResource}/.default" };

            BuildAuthApplicationCert(environment, clientId, certificate, logger);
            AuthenticationResult result = null;

            try
            {
                var accounts = await this.AuthApplicationCert.GetAccountsAsync();
                if (accounts != null && accounts.Any())
                {
                    // This indicates there's token in cache
                    result = await this.AuthApplicationCert.AcquireTokenSilent(scopes, accounts.FirstOrDefault()).ExecuteAsync();
                }
                else
                {
                    BuildAuthApplicationCert(environment, clientId, certificate, logger);
                    result = await this.AuthApplicationCert.AcquireTokenForClient(scopes).ExecuteAsync();
                }
            }
            catch (Exception ex)
            {
                throw new AuthenticationException($"Error Acquiring Token:{System.Environment.NewLine}{ex}");
            }

            if (result != null)
            {
                return result.ToIAccessToken();
                // Use the token
            }
            else
            {
                throw new AuthenticationException("Failed to acquire token");
            }
        }