Exemple #1
0
        public void KnownMetadataProvider_publicEnvironment()
        {
            Assert.IsFalse(KnownMetadataProvider.IsPublicEnvironment(""));
            Assert.IsFalse(KnownMetadataProvider.IsPublicEnvironment(null));
            Assert.IsFalse(KnownMetadataProvider.IsPublicEnvironment("unknown"));
            Assert.IsFalse(KnownMetadataProvider.IsPublicEnvironment("login.microsoftonline.de"));

            Assert.IsTrue(KnownMetadataProvider.IsPublicEnvironment("login.microsoft.com"));
            Assert.IsTrue(KnownMetadataProvider.IsPublicEnvironment("login.microsoftonline.com"));
            Assert.IsTrue(KnownMetadataProvider.IsPublicEnvironment("Login.microsoftonline.com"));
        }
Exemple #2
0
        private string GetRegionalizedEnviroment(Uri authority, string region)
        {
            var builder = new UriBuilder(authority);

            // special rule for Global cloud
            if (KnownMetadataProvider.IsPublicEnvironment(authority.Host))
            {
                return($"{region}.login.microsoft.com");
            }

            return($"{region}.{builder.Host}");
        }
        private async Task <Uri> BuildAuthorityWithRegionAsync(Uri canonicalAuthority, RequestContext requestContext)
        {
            string regionToUse = requestContext.ServiceBundle.Config.AuthorityInfo.RegionToUse;

            if (s_region.IsNullOrEmpty())
            {
                try
                {
                    s_region = await GetRegionAsync(requestContext).ConfigureAwait(false);

                    if (!regionToUse.IsNullOrEmpty())
                    {
                        requestContext.ApiEvent.IsValidUserProvidedRegion = s_region.Equals(regionToUse);
                        requestContext.Logger.Info($"The auto detected region is {s_region}.");
                        if (s_region.Equals(regionToUse))
                        {
                            requestContext.Logger.Info("The region provided by the user is valid and equal to the auto detected region.");
                        }
                        else
                        {
                            requestContext.Logger.Info($"The region provided by the user is invalid. Region detected: {s_region} Region provided: {regionToUse}");
                        }
                    }
                }
                catch (MsalServiceException e)
                {
                    if (regionToUse.IsNullOrEmpty())
                    {
                        throw e;
                    }

                    s_region = regionToUse;
                    requestContext.Logger.Info($"Region auto detection failed. Region provided by the user will be used: ${regionToUse}.");
                    LogTelemetryData(s_region, RegionSource.UserProvided, requestContext);
                }
            }

            var builder = new UriBuilder(canonicalAuthority);

            if (KnownMetadataProvider.IsPublicEnvironment(canonicalAuthority.Host))
            {
                builder.Host = $"{s_region}.login.microsoft.com";
            }
            else
            {
                builder.Host = $"{s_region}.{builder.Host}";
            }

            return(builder.Uri);
        }
        private async Task <Uri> BuildAuthorityWithRegionAsync(Uri canonicalAuthority, RequestContext requestContext)
        {
            string region = await GetRegionAsync(requestContext).ConfigureAwait(false);

            var builder = new UriBuilder(canonicalAuthority);

            if (KnownMetadataProvider.IsPublicEnvironment(canonicalAuthority.Host))
            {
                builder.Host = $"{region}.login.microsoft.com";
            }
            else
            {
                builder.Host = $"{region}.{builder.Host}";
            }

            return(builder.Uri);
        }
Exemple #5
0
        private string GetRegionalizedEnviroment(Uri authority, string region)
        {
            string host = authority.Host;

            if (KnownMetadataProvider.IsPublicEnvironment(host))
            {
                return($"{region}.{PublicEnvForRegional}");
            }

            // Regional business rule - use the PreferredNetwork value for public and sovereign clouds
            // but do not do instance discovery for it - rely on cached values only
            if (KnownMetadataProvider.TryGetKnownEnviromentPreferredNetwork(host, out var preferredNetworkEnv))
            {
                host = preferredNetworkEnv;
            }

            return($"{region}.{host}");
        }