public static async Task<Models.CachedAccessToken> GetAccessTokenAsync(string tenantId, string resource, bool useDogfood)
        {
            IAppConfig app = /*useDogfood ? new DogfoodAppConfig() :*/ new ProductionAppConfig();

            string authority = app.AuthorizationServiceUri.Replace("common", tenantId);
            AuthenticationContext authContext = new AuthenticationContext(authority, false);


            var certDataBase64 = ConfigurationManager.AppSettings["PrivateCertificateBase64"];
            var certBinaryData = Convert.FromBase64String(certDataBase64);
            var password = ConfigurationManager.AppSettings["CertificatePassword"];

            X509Certificate2 cert = new X509Certificate2(certBinaryData, password, X509KeyStorageFlags.MachineKeySet);

            var clientAppId = ConfigurationManager.AppSettings["ClientAppId"];

            ClientAssertionCertificate cac = new ClientAssertionCertificate(clientAppId, cert);

            var authenticationResult = await authContext.AcquireTokenAsync(resource, cac);
            return new Models.CachedAccessToken(authenticationResult.AccessToken, authenticationResult.ExpiresOn);
        }
        public static async Task <Models.CachedAccessToken> GetAccessTokenAsync(string tenantId, string resource, bool useDogfood)
        {
            IAppConfig app = /*useDogfood ? new DogfoodAppConfig() :*/ new ProductionAppConfig();

            string authority = app.AuthorizationServiceUri.Replace("common", tenantId);
            AuthenticationContext authContext = new AuthenticationContext(authority, false);


            var certDataBase64 = ConfigurationManager.AppSettings["PrivateCertificateBase64"];
            var certBinaryData = Convert.FromBase64String(certDataBase64);
            var password       = ConfigurationManager.AppSettings["CertificatePassword"];

            X509Certificate2 cert = new X509Certificate2(certBinaryData, password, X509KeyStorageFlags.MachineKeySet);

            var clientAppId = ConfigurationManager.AppSettings["ClientAppId"];

            ClientAssertionCertificate cac = new ClientAssertionCertificate(clientAppId, cert);

            var authenticationResult = await authContext.AcquireTokenAsync(resource, cac);

            return(new Models.CachedAccessToken(authenticationResult.AccessToken, authenticationResult.ExpiresOn));
        }