Пример #1
0
        /// <summary>
        /// Authenticates the user with the specified AD FS endpoint and
        /// yields the SAML response data for subsequent parsing.
        /// </summary>
        /// <param name="identityProvider">
        /// The https endpoint of the federated identity provider.
        /// </param>
        /// <param name="credentials">
        /// Credentials for the call. If null, the user's default network credentials
        /// will be used in a temporary impersonation context.
        /// </param>
        /// <param name="authenticationType">
        /// The authentication type to be used with the endpoint. Valid values are 'NTLM',
        /// 'Digest', 'Kerberos' and 'Negotiate'.
        /// </param>
        /// <param name="proxySettings">Null or configured proxy settings for the HTTPS call.</param>
        /// <returns>The response data from a successful authentication request.</returns>
        public string Authenticate(Uri identityProvider, ICredentials credentials, string authenticationType, WebProxy proxySettings)
        {
            string             responseStreamData = null;
            ImpersonationState impersonationState = null;

            try
            {
                if (credentials != null)
                {
                    var networkCredentials = credentials.GetCredential(identityProvider, authenticationType);
                    impersonationState = ImpersonationState.Impersonate(networkCredentials);
                }

                using (var response = QueryProvider(identityProvider, authenticationType, proxySettings))
                {
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        responseStreamData = reader.ReadToEnd();
                    }
                }
            }
            catch (Exception e)
            {
                throw new AdfsAuthenticationControllerException(e.ToString(), e);
            }
            finally
            {
                if (impersonationState != null)
                {
                    impersonationState.Dispose();
                }
            }

            return(responseStreamData);
        }
Пример #2
0
        /// <summary>
        /// Authenticates the user with the specified AD FS endpoint and
        /// yields the SAML response data for subsequent parsing.
        /// </summary>
        /// <param name="identityProvider">
        /// The https endpoint of the federated identity provider.
        /// </param>
        /// <param name="credentials">
        /// Credentials for the call. If null, the user's default network credentials
        /// will be used in a temporary impersonation context.
        /// </param>
        /// <param name="authenticationType">
        /// The authentication type to be used with the endpoint. Valid values are 'NTLM',
        /// 'Digest', 'Kerberos' and 'Negotiate'.
        /// </param>
        /// <returns>The response data from a successful authentication request.</returns>
        public string Authenticate(Uri identityProvider, ICredentials credentials, string authenticationType)
        {
            string             responseStreamData = null;
            ImpersonationState impersonationState = null;

            try
            {
                if (credentials != null)
                {
                    var networkCredentials = credentials.GetCredential(identityProvider, authenticationType);
                    impersonationState = ImpersonationState.Impersonate(networkCredentials);
                }

                using (var response = QueryProvider(identityProvider, authenticationType))
                {
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        responseStreamData = reader.ReadToEnd();
                    }
                }
            }
            catch (Exception e)
            {
                var sb = new StringBuilder(e.Message);
                if (e.InnerException != null)
                {
                    sb.AppendFormat("(Inner exception '{0}')", e.InnerException.Message);
                }
                throw new AdfsAuthenticationControllerException(sb.ToString(), e);
            }
            finally
            {
                if (impersonationState != null)
                {
                    impersonationState.Dispose();
                }
            }

            return(responseStreamData);
        }