#pragma warning disable UseAsyncSuffix // Use Async suffix
        public async Task <long> Get()
#pragma warning restore UseAsyncSuffix // Use Async suffix
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            Guid          requestId = Guid.NewGuid();
            StringBuilder sb        = new StringBuilder();


            ConfidentialClientApplication local_cca = ConfidentialClientApplicationBuilder
                                                      .Create("d3adb33f-c0de-ed0c-c0de-deadb33fc0d3")
                                                      .WithAuthority($"https://login.microsoftonline.com/tid")
                                                      .WithHttpManager(s_httpManager)
                                                      .WithClientSecret("secret")
                                                      .WithLegacyCacheCompatibility(false)
                                                      .WithLogging((lvl, msg, pii) => sb.AppendLine(msg), LogLevel.Verbose, true, false)
                                                      .BuildConcrete();

            ConfidentialClientApplication cca = local_cca;


            var user = $"user_{s_random.Next(Settings.NumberOfUsers)}";

            s_inMemoryPartitionedCacheSerializer.Initialize(cca.UserTokenCache as TokenCache);

            string fakeUpstreamToken = $"upstream_token_{user}";


            var res = await cca.AcquireTokenOnBehalfOf(new[] { "scope" }, new UserAssertion(fakeUpstreamToken))
                      .WithCorrelationId(requestId)
                      .ExecuteAsync()
                      .ConfigureAwait(false);

            sw.Stop();

            TraceResult(res, user, sw.ElapsedMilliseconds);

            // Log the very bad requests
            if (res.AuthenticationResultMetadata.DurationTotalInMs > 2 * 1000 || sw.ElapsedMilliseconds > 2 * 1000)
            {
                s_traceSource.TraceEvent(TraceEventType.Error, 1, "##### FOUND!! " + requestId);


                System.IO.File.WriteAllText($"c:\\temp\\obo_{requestId}.txt", sb.ToString());
                System.IO.File.WriteAllText($"c:\\temp\\obo2_{requestId}.txt", sb2.ToString());
            }

            return(res.AuthenticationResultMetadata.DurationTotalInMs);
        }
Example #2
0
#pragma warning disable UseAsyncSuffix // Use Async suffix
        public async Task <ActionResult <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")
                      .WithHttpManager(httpManager)
                      .WithAuthority($"https://login.microsoftonline.com/{tid}")
                      .WithClientSecret("secret")
                      .BuildConcrete();

            s_inMemoryPartitionedCacheSerializer.Initialize(cca.AppTokenCache as TokenCache);


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

            return(res.AuthenticationResultMetadata.DurationTotalInMs);
        }