private async Task <InstanceDiscoveryResponse> SendInstanceDiscoveryRequestAsync(
            Uri authority,
            RequestContext requestContext)
        {
            var client = new OAuth2Client(requestContext.Logger, _httpManager, _telemetryManager);

            client.AddQueryParameter("api-version", "1.1");
            client.AddQueryParameter("authorization_endpoint", BuildAuthorizeEndpoint(authority.Host, GetTenant(authority)));

            string discoveryHost = KnownMetadataProvider.IsKnownEnvironment(authority.Host) ?
                                   authority.Host :
                                   AadAuthority.DefaultTrustedHost;

            string instanceDiscoveryEndpoint = BuildInstanceDiscoveryEndpoint(discoveryHost);

            InstanceDiscoveryResponse discoveryResponse = await client
                                                          .DiscoverAadInstanceAsync(new Uri(instanceDiscoveryEndpoint), requestContext)
                                                          .ConfigureAwait(false);

            return(discoveryResponse);
        }
Ejemplo n.º 2
0
        private Uri ComputeHttpEndpoint(Uri authority, RequestContext requestContext)
        {
            if (_userProvidedInstanceDiscoveryUri != null)
            {
                return(_userProvidedInstanceDiscoveryUri);
            }

            string discoveryHost = KnownMetadataProvider.IsKnownEnvironment(authority.Host) ?
                                   authority.Host :
                                   AadAuthority.DefaultTrustedHost;

            string instanceDiscoveryEndpoint = UriBuilderExtensions.GetHttpsUriWithOptionalPort(
                string.Format(
                    CultureInfo.InvariantCulture,
                    "https://{0}/common/discovery/instance",
                    discoveryHost),
                authority.Port);

            requestContext.Logger.InfoPii(
                $"Fetching instance discovery from the network from host {discoveryHost}. Endpoint {instanceDiscoveryEndpoint}",
                $"Fetching instance discovery from the network from host {discoveryHost}");

            return(new Uri(instanceDiscoveryEndpoint));
        }