internal static async Task<UserRealmDiscoveryResponse> CreateByDiscoveryAsync(string userRealmUri, string userName, CallState callState)
        {
            string userRealmEndpoint = userRealmUri;
            userRealmEndpoint += (userName + "?api-version=1.0");

            PlatformPlugin.Logger.Information(callState, string.Format("Sending user realm discovery request to '{0}'", userRealmEndpoint));

            var client = new AdalHttpClient(userRealmEndpoint, callState) { Client = { Accept = "application/json" } };
            return await client.GetResponseAsync<UserRealmDiscoveryResponse>(ClientMetricsEndpointType.UserRealmDiscovery);
        }
Exemple #2
0
        private async Task <AuthenticationResultEx> SendHttpMessageAsync(IRequestParameters requestParameters)
        {
            client = new AdalHttpClient(this.Authenticator.TokenUri, this.CallState)
            {
                Client = { BodyParameters = requestParameters }
            };
            TokenResponse tokenResponse = await client.GetResponseAsync <TokenResponse>().ConfigureAwait(false);

            return(tokenResponse.GetResult());
        }
        internal async Task <DeviceCodeResult> RunHandlerAsync()
        {
            await this.authenticator.UpdateFromTemplateAsync(this.callState).ConfigureAwait(false);

            this.ValidateAuthorityType();
            AdalHttpClient     client   = new AdalHttpClient(CreateDeviceCodeRequestUriString(), this.callState);
            DeviceCodeResponse response = await client.GetResponseAsync <DeviceCodeResponse>().ConfigureAwait(false);

            if (!string.IsNullOrEmpty(response.Error))
            {
                throw new AdalException(response.Error, response.ErrorDescription);
            }

            return(response.GetResult(clientKey.ClientId, resource));
        }
Exemple #4
0
        internal static async Task <UserRealmDiscoveryResponse> CreateByDiscoveryAsync(string userRealmUri, string userName, CallState callState)
        {
            string userRealmEndpoint = userRealmUri;

            userRealmEndpoint += (userName + "?api-version=1.0");

            var msg = "Sending request to userrealm endpoint.";

            callState.Logger.Information(callState, msg);
            callState.Logger.InformationPii(callState, msg);

            var client = new AdalHttpClient(userRealmEndpoint, callState)
            {
                Client = { Accept = "application/json" }
            };

            return(await client.GetResponseAsync <UserRealmDiscoveryResponse>().ConfigureAwait(false));
        }
        public async Task VerifyAnotherHostByInstanceDiscoveryAsync(string host, string tenant, CallState callState)
        {
            string instanceDiscoveryEndpoint = this.InstanceDiscoveryEndpoint;
            instanceDiscoveryEndpoint += ("?api-version=1.0&authorization_endpoint=" + AuthorizeEndpointTemplate);
            instanceDiscoveryEndpoint = instanceDiscoveryEndpoint.Replace("{host}", host);
            instanceDiscoveryEndpoint = instanceDiscoveryEndpoint.Replace("{tenant}", tenant);

            try
            {
                var client = new AdalHttpClient(instanceDiscoveryEndpoint, callState);
                InstanceDiscoveryResponse discoveryResponse = await client.GetResponseAsync<InstanceDiscoveryResponse>(ClientMetricsEndpointType.InstanceDiscovery);

                if (discoveryResponse.TenantDiscoveryEndpoint == null)
                {
                    throw new AdalException(AdalError.AuthorityNotInValidList);
                }
            }
            catch (AdalServiceException ex)
            {
                throw new AdalException((ex.ErrorCode == "invalid_instance") ? AdalError.AuthorityNotInValidList : AdalError.AuthorityValidationFailed, ex);
            }
        }
        private async Task<AuthenticationResultEx> SendHttpMessageAsync(IRequestParameters requestParameters)
        {
            var client = new AdalHttpClient(this.Authenticator.TokenUri, this.CallState) { Client = { BodyParameters = requestParameters } };
            TokenResponse tokenResponse = await client.GetResponseAsync<TokenResponse>(ClientMetricsEndpointType.Token);

            return tokenResponse.GetResult();
        }
        private async Task<List<AuthenticationResultEx>> SendHttpMessageAsync(IRequestParameters requestParameters, string extraQueryParameters = null)
        {
            string uri = this.Authenticator.TokenUri;
            if (!string.IsNullOrEmpty(extraQueryParameters))
            {
                uri = uri + "?" + extraQueryParameters;
            }

            var client = new AdalHttpClient(uri, this.CallState)
            {
                Client = {BodyParameters = requestParameters}
            };
            TokenResponse tokenResponse = await client.GetResponseAsync<TokenResponse>(ClientMetricsEndpointType.Token);

            return tokenResponse.GetResults();
        }