public async Task <InstanceDiscoveryMetadataEntry> GetMetadataEntryTryAvoidNetworkAsync( AuthorityInfo authorityInfo, IEnumerable <string> existingEnvironmentsInCache, RequestContext requestContext) { string environment = authorityInfo.Host; switch (authorityInfo.AuthorityType) { case AuthorityType.Aad: 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)); case AuthorityType.Adfs: case AuthorityType.B2C: requestContext.Logger.Info("[Instance Discovery] Skipping Instance discovery for non-AAD authority. "); return(await GetMetadataEntryAsync(authorityInfo, requestContext).ConfigureAwait(false)); default: throw new InvalidOperationException("Unexpected authority type " + authorityInfo.AuthorityType); } }
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> GetMetadataEntryAsync( string authority, RequestContext requestContext) { var autoDetectRegion = requestContext.ServiceBundle.Config.AuthorityInfo.AutoDetectRegion; if (autoDetectRegion) { return(await _regionDiscoveryProvider.GetMetadataAsync(new Uri(authority), requestContext).ConfigureAwait(false)); } AuthorityType type = Authority.GetAuthorityType(authority); Uri authorityUri = new Uri(authority); string environment = authorityUri.Host; switch (type) { case AuthorityType.Aad: InstanceDiscoveryMetadataEntry entry = _userMetadataProvider?.GetMetadataOrThrow(environment, requestContext.Logger) ?? // if user provided metadata but entry is not found, fail fast await FetchNetworkMetadataOrFallbackAsync(requestContext, authorityUri).ConfigureAwait(false); if (entry == null) { string message = "[Instance Discovery] Instance metadata for this authority could neither be fetched nor found. MSAL will continue regardless. SSO might be broken if authority aliases exist. "; requestContext.Logger.WarningPii(message + "Authority: " + authority, message); entry = CreateEntryForSingleAuthority(authorityUri); } return(entry); // ADFS and B2C do not support instance discovery case AuthorityType.Adfs: case AuthorityType.B2C: requestContext.Logger.Info("[Instance Discovery] Skipping Instance discovery for non-AAD authority. "); return(CreateEntryForSingleAuthority(authorityUri)); default: throw new InvalidOperationException("Unexpected authority type " + type); } }
public async Task SuccessfulResponseFromEnvironmentVariableAsync() { Environment.SetEnvironmentVariable(TestConstants.RegionName, TestConstants.Region); _testRequestContext.ServiceBundle.Config.AzureRegion = null; // not configured InstanceDiscoveryMetadataEntry regionalMetadata = await _regionDiscoveryProvider.GetMetadataAsync( new Uri("https://login.microsoftonline.com/common/"), _testRequestContext) .ConfigureAwait(false); Assert.IsNull(regionalMetadata); }