public async Task DifferentHostsAsync() { _harness.HttpManager.AddInstanceDiscoveryMockHandler(); _testRequestContext.ServiceBundle.Config.HttpManager = _harness.HttpManager; _testRequestContext.ServiceBundle.Config.AuthorityInfo = s_commonAuthority; var ex = await Assert.ThrowsExceptionAsync <MsalClientException>( () => Authority.CreateAuthorityForRequestAsync(_testRequestContext, s_ppeAuthority, null)).ConfigureAwait(false); Assert.AreEqual(MsalError.AuthorityHostMismatch, ex.ErrorCode); _harness.HttpManager.AddInstanceDiscoveryMockHandler(); _testRequestContext.ServiceBundle.Config.AuthorityInfo = s_ppeAuthority; var ex2 = await Assert.ThrowsExceptionAsync <MsalClientException>( () => Authority.CreateAuthorityForRequestAsync(_testRequestContext, s_commonAuthority, null)).ConfigureAwait(false); Assert.AreEqual(MsalError.AuthorityHostMismatch, ex2.ErrorCode); _testRequestContext.ServiceBundle.Config.AuthorityInfo = AuthorityInfo.FromAdfsAuthority(TestConstants.ADFSAuthority, true); var ex3 = await Assert.ThrowsExceptionAsync <MsalClientException>( () => Authority.CreateAuthorityForRequestAsync( _testRequestContext, AuthorityInfo.FromAdfsAuthority(TestConstants.ADFSAuthority2, true), null)).ConfigureAwait(false); Assert.AreEqual(MsalError.AuthorityHostMismatch, ex3.ErrorCode); _testRequestContext.ServiceBundle.Config.AuthorityInfo = AuthorityInfo.FromAuthorityUri(TestConstants.B2CAuthority, true); var ex4 = await Assert.ThrowsExceptionAsync <MsalClientException>( () => Authority.CreateAuthorityForRequestAsync( _testRequestContext, AuthorityInfo.FromAuthorityUri(TestConstants.B2CCustomDomain, true), null)).ConfigureAwait(false); Assert.AreEqual(MsalError.B2CAuthorityHostMismatch, ex4.ErrorCode); }
public async Task DefaultAuthorityDifferentTypeTestAsync() { _testRequestContext.ServiceBundle.Config.AuthorityInfo = s_commonAuthority; var ex = await Assert.ThrowsExceptionAsync <MsalClientException>( () => Authority.CreateAuthorityForRequestAsync(_testRequestContext, s_b2cAuthority, null)).ConfigureAwait(false); Assert.AreEqual(MsalError.B2CAuthorityHostMismatch, ex.ErrorCode); }
public async Task AuthorityMismatchTestAsync() { _testRequestContext.ServiceBundle.Config.AuthorityInfo = s_utidAuthority; var ex = await AssertException.TaskThrowsAsync <MsalClientException>( () => Authority.CreateAuthorityForRequestAsync(_testRequestContext, s_b2cAuthority, null)) .ConfigureAwait(false); Assert.AreEqual(MsalError.AuthorityTypeMismatch, ex.ErrorCode); }
private static void VerifyAuthority( AuthorityInfo config, AuthorityInfo request, string accountTid, string resultTid, RequestContext requestContext) { requestContext.ServiceBundle.Config.AuthorityInfo = config; var resultAuthority = Authority.CreateAuthorityForRequestAsync(requestContext, request, accountTid).Result; Assert.AreEqual(resultTid, resultAuthority.TenantId); }
public async Task DifferentHostsWithAliasedAuthorityAsync() { //Checking for aliased authority. Should not throw exception whan a developer configures an authority on the application //but uses a different authority that is a known alias of the previously configured one. //See https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/issues/2736 _harness.HttpManager.AddInstanceDiscoveryMockHandler(TestConstants.PrefCacheAuthorityCommonTenant); _testRequestContext.ServiceBundle.Config.HttpManager = _harness.HttpManager; _testRequestContext.ServiceBundle.Config.AuthorityInfo = s_commonNetAuthority; var authority = await Authority.CreateAuthorityForRequestAsync(_testRequestContext, s_commonAuthority).ConfigureAwait(false); Assert.AreEqual(s_commonNetAuthority.CanonicalAuthority, authority.AuthorityInfo.CanonicalAuthority); }
private async Task UpdateRequestWithAccountAsync() { IAccount account = await GetAccountFromParamsOrLoginHintAsync( _silentParameters.Account, _silentParameters.LoginHint).ConfigureAwait(false); AuthenticationRequestParameters.Account = account; // AcquireTokenSilent must not use "common" or "organizations". Instead, use the home tenant id. var tenantedAuthority = await Authority.CreateAuthorityForRequestAsync( AuthenticationRequestParameters.RequestContext, AuthenticationRequestParameters.AuthorityOverride, account?.HomeAccountId?.TenantId).ConfigureAwait(false); AuthenticationRequestParameters.AuthorityManager = new AuthorityManager( AuthenticationRequestParameters.RequestContext, tenantedAuthority); }