public async Task ForceRefreshParameterFalseTestAsync() { using (var httpManager = new MockHttpManager()) { httpManager.AddInstanceDiscoveryMockHandler(); var app = ConfidentialClientApplicationBuilder .Create(MsalTestConstants.ClientId) .WithAuthority(new Uri(MsalTestConstants.AuthorityTestTenant), true) .WithRedirectUri(MsalTestConstants.RedirectUri) .WithClientSecret(MsalTestConstants.ClientSecret) .WithHttpManager(httpManager) .BuildConcrete(); _tokenCacheHelper.PopulateCacheForClientCredential(app.AppTokenCacheInternal.Accessor); var accessTokens = await app.AppTokenCacheInternal.GetAllAccessTokensAsync(true).ConfigureAwait(false); var accessTokenInCache = accessTokens .Where(item => ScopeHelper.ScopeContains(item.ScopeSet, MsalTestConstants.Scope)) .ToList().FirstOrDefault(); // Don't add mock to fail in case of network call // If there's a network call by mistake, then there won't be a proper number // of mock web request/response objects in the queue and we'll fail. var result = await app .AcquireTokenForClient(MsalTestConstants.Scope) .WithForceRefresh(false) .ExecuteAsync(CancellationToken.None) .ConfigureAwait(false); Assert.AreEqual(accessTokenInCache.Secret, result.AccessToken); } }
public void GlobalSetup() { var cca = ConfidentialClientApplicationBuilder .Create(TestConstants.ClientId) .WithAuthority(new Uri(TestConstants.AuthorityTestTenant)) .WithRedirectUri(TestConstants.RedirectUri) .WithClientSecret(TestConstants.ClientSecret) .BuildConcrete(); var inMemoryTokenCache = new InMemoryTokenCache(); inMemoryTokenCache.Bind(cca.AppTokenCache); TokenCacheHelper tokenCacheHelper = new TokenCacheHelper(); tokenCacheHelper.PopulateCacheForClientCredential(cca.AppTokenCacheInternal.Accessor, TokenCacheSize); _acquireTokenForClientBuilder = cca .AcquireTokenForClient(TestConstants.s_scope) .WithForceRefresh(false); }
public async Task ForceRefreshParameterFalseTestAsync() { await RunWithMockHttpAsync( async (httpManager, serviceBundle, receiver) => { httpManager.AddInstanceDiscoveryMockHandler(); var cache = new TokenCache(); _tokenCacheHelper.PopulateCacheForClientCredential(cache.TokenCacheAccessor); string authority = Authority.CreateAuthority(serviceBundle, MsalTestConstants.AuthorityTestTenant, false) .CanonicalAuthority; var app = new ConfidentialClientApplication( serviceBundle, MsalTestConstants.ClientId, authority, MsalTestConstants.RedirectUri, new ClientCredential(MsalTestConstants.ClientSecret), null, cache) { ValidateAuthority = false }; ICollection <MsalAccessTokenCacheItem> accessTokens = cache.GetAllAccessTokensForClient(new RequestContext(null, new MsalLogger(Guid.NewGuid(), null))); var accessTokenInCache = accessTokens .Where(item => ScopeHelper.ScopeContains(item.ScopeSet, MsalTestConstants.Scope)) .ToList().FirstOrDefault(); // Don't add mock to fail in case of network call // If there's a network call by mistake, then there won't be a proper number // of mock web request/response objects in the queue and we'll fail. var result = await app.AcquireTokenForClientAsync(MsalTestConstants.Scope, false).ConfigureAwait(false); Assert.AreEqual(accessTokenInCache.Secret, result.AccessToken); }).ConfigureAwait(false); }