public async Task <InstanceDiscoveryMetadataEntry> GetMetadataEntryTryAvoidNetworkAsync( string authority, IEnumerable <string> existingEnvironmentsInCache, RequestContext requestContext) { AuthorityType type = Authority.GetAuthorityType(authority); Uri authorityUri = new Uri(authority); string environment = authorityUri.Host; switch (type) { case AuthorityType.Aad: return (_userMetadataProvider?.GetMetadataOrThrow(environment, requestContext.Logger) ?? // if user provided metadata but entry is not found, fail fast _networkCacheMetadataProvider.GetMetadata(environment, requestContext.Logger) ?? _knownMetadataProvider.GetMetadata(environment, existingEnvironmentsInCache, requestContext.Logger) ?? await GetMetadataEntryAsync(authority, requestContext).ConfigureAwait(false)); case AuthorityType.Adfs: case AuthorityType.B2C: requestContext.Logger.Info("[Instance Discovery] Skipping Instance discovery for non-AAD authority"); return(await GetMetadataEntryAsync(authority, requestContext).ConfigureAwait(false)); default: throw new InvalidOperationException("Unexpected authority type " + type); } }
public async Task KnownMetadataProviderIsCheckedSecondAsync() { // Arrange var otherEnvs = new[] { "env1", "env2" }; // No response from the static provider _staticMetadataProvider.GetMetadata("some_env.com").Returns((InstanceDiscoveryMetadataEntry)null); _knownMetadataProvider.GetMetadata("some_env.com", otherEnvs).Returns(_expectedResult); // Act InstanceDiscoveryMetadataEntry actualResult = await _discoveryManager.GetMetadataEntryTryAvoidNetworkAsync( "https://some_env.com/tid", otherEnvs, _testRequestContext) .ConfigureAwait(false); // Assert Assert.AreSame(_expectedResult, actualResult, "The known metadata provider should be queried second"); _staticMetadataProvider.Received(1).GetMetadata("some_env.com"); _knownMetadataProvider.Received(1).GetMetadata("some_env.com", otherEnvs); }
public async Task <InstanceDiscoveryMetadataEntry> GetMetadataEntryTryAvoidNetworkAsync( AuthorityInfo authorityInfo, IEnumerable <string> existingEnvironmentsInCache, RequestContext requestContext) { string environment = authorityInfo.Host; if (authorityInfo.IsInstanceDiscoverySupported) { return (_userMetadataProvider?.GetMetadataOrThrow(environment, requestContext.Logger) ?? // if user provided metadata but entry is not found, fail fast await _regionDiscoveryProvider.GetMetadataAsync(new Uri(authorityInfo.CanonicalAuthority), requestContext).ConfigureAwait(false) ?? _networkCacheMetadataProvider.GetMetadata(environment, requestContext.Logger) ?? _knownMetadataProvider.GetMetadata(environment, existingEnvironmentsInCache, requestContext.Logger) ?? await GetMetadataEntryAsync(authorityInfo, requestContext).ConfigureAwait(false)); } else { requestContext.Logger.Info($"Skipping Instance discovery for {authorityInfo.AuthorityType} authority"); return(await GetMetadataEntryAsync(authorityInfo, requestContext).ConfigureAwait(false)); } }
public async Task <InstanceDiscoveryMetadataEntry> GetMetadataEntryTryAvoidNetworkAsync( string authority, IEnumerable <string> existingEnvironmentsInCache, RequestContext requestContext) { AuthorityType type = Authority.GetAuthorityType(authority); Uri authorityUri = new Uri(authority); string environment = authorityUri.Host; switch (type) { case AuthorityType.Aad: InstanceDiscoveryMetadataEntry entry = _staticMetadataProvider.GetMetadata(environment); if (entry != null) { return(entry); } entry = _knownMetadataProvider.GetMetadata(environment, existingEnvironmentsInCache); if (entry != null) { return(entry); } return(await GetMetadataEntryAsync(authority, requestContext).ConfigureAwait(false)); case AuthorityType.Adfs: case AuthorityType.B2C: return(await GetMetadataEntryAsync(authority, requestContext).ConfigureAwait(false)); default: throw new InvalidOperationException("Unexpected authority type " + type); } }