#pragma warning disable UseAsyncSuffix // Use Async suffix
        public async Task <long> Get()
#pragma warning restore UseAsyncSuffix // Use Async suffix
        {
            var  tid      = $"tid{s_random.Next(Settings.NumberOfTenants)}";
            bool cacheHit = s_random.NextDouble() <= Settings.CacheHitRatio;

            S2SParallelRequestMockHandler httpManager = new S2SParallelRequestMockHandler();

            var cca = ConfidentialClientApplicationBuilder
                      .Create("d3adb33f-c0de-ed0c-c0de-deadb33fc0d3")
                      .WithAuthority($"https://login.microsoftonline.com/{tid}")
                      .WithHttpManager(httpManager)
                      .WithClientSecret("secret")
                      .BuildConcrete();

            s_msalCache.Initialize(cca.AppTokenCache as TokenCache);


            var res = await cca.AcquireTokenForClient(new[] { "scope" })
                      .WithForceRefresh(!cacheHit)
                      .ExecuteAsync().ConfigureAwait(false);

            if (res.AccessToken != tid)
            {
                throw new InvalidOperationException("failed");
            }

            return(res.AuthenticationResultMetadata.DurationTotalInMs);
        }
Exemplo n.º 2
0
        private static ConfidentialClientApplication CreateCCA()
        {
            S2SParallelRequestMockHandler httpManager = new S2SParallelRequestMockHandler();

            return(ConfidentialClientApplicationBuilder
                   .Create("d3adb33f-c0de-ed0c-c0de-deadb33fc0d3")
                   .WithHttpManager(httpManager)
                   .WithClientSecret("secret")
                   .BuildConcrete());
        }