コード例 #1
0
        /// <summary>
        /// Processes an authentication request by a popup window.
        /// </summary>
        /// <param name="userIdentityPageBase">The base URI upon which user identity pages are created.</param>
        /// <param name="request">The incoming authentication request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// A task that completes with the asynchronous operation.
        /// </returns>
        internal static async Task ProcessAuthenticationAsync(Uri userIdentityPageBase, IAuthenticationRequest request, CancellationToken cancellationToken)
        {
            Requires.NotNull(userIdentityPageBase, "userIdentityPageBase");
            Requires.NotNull(request, "request");

            var window = new CheckIdWindow(userIdentityPageBase, request);

            IHostFactories hostFactories    = new DefaultOpenIdHostFactories();
            bool           isRPDiscoverable = await request.IsReturnUrlDiscoverableAsync(hostFactories, cancellationToken) == RelyingPartyDiscoveryResult.Success;

            window.discoverableYesLabel.Visibility = isRPDiscoverable ? Visibility.Visible : Visibility.Collapsed;
            window.discoverableNoLabel.Visibility  = isRPDiscoverable ? Visibility.Collapsed : Visibility.Visible;

            bool?result = window.ShowDialog();

            // If the user pressed Esc or cancel, just send a negative assertion.
            if (!result.HasValue || !result.Value)
            {
                request.IsAuthenticated = false;
                return;
            }

            request.IsAuthenticated = window.tabControl1.SelectedItem == window.positiveTab;
            if (request.IsAuthenticated.Value)
            {
                request.ClaimedIdentifier = window.claimedIdentifierBox.Text;
                request.LocalIdentifier   = window.localIdentifierBox.Text;
            }
        }
コード例 #2
0
		/// <summary>
		/// Processes an authentication request by a popup window.
		/// </summary>
		/// <param name="userIdentityPageBase">The base URI upon which user identity pages are created.</param>
		/// <param name="request">The incoming authentication request.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <returns>
		/// A task that completes with the asynchronous operation.
		/// </returns>
		internal static async Task ProcessAuthenticationAsync(Uri userIdentityPageBase, IAuthenticationRequest request, CancellationToken cancellationToken) {
			Requires.NotNull(userIdentityPageBase, "userIdentityPageBase");
			Requires.NotNull(request, "request");

			var window = new CheckIdWindow(userIdentityPageBase, request);

			IHostFactories hostFactories = new DefaultOpenIdHostFactories();
			bool isRPDiscoverable = await request.IsReturnUrlDiscoverableAsync(hostFactories, cancellationToken) == RelyingPartyDiscoveryResult.Success;
			window.discoverableYesLabel.Visibility = isRPDiscoverable ? Visibility.Visible : Visibility.Collapsed;
			window.discoverableNoLabel.Visibility = isRPDiscoverable ? Visibility.Collapsed : Visibility.Visible;

			bool? result = window.ShowDialog();

			// If the user pressed Esc or cancel, just send a negative assertion.
			if (!result.HasValue || !result.Value) {
				request.IsAuthenticated = false;
				return;
			}

			request.IsAuthenticated = window.tabControl1.SelectedItem == window.positiveTab;
			if (request.IsAuthenticated.Value) {
				request.ClaimedIdentifier = window.claimedIdentifierBox.Text;
				request.LocalIdentifier = window.localIdentifierBox.Text;
			}
		}
コード例 #3
0
        /// <summary>
        /// Processes an incoming request at the OpenID Provider endpoint.
        /// </summary>
        /// <param name="requestInfo">The request info.</param>
        /// <param name="response">The response.</param>
        private void ProcessRequest(HttpRequestInfo requestInfo, HttpListenerResponse response)
        {
            IRequest request = this.hostedProvider.Provider.GetRequest(requestInfo);

            if (request == null)
            {
                App.Logger.Error("A request came in that did not carry an OpenID message.");
                response.ContentType = "text/html";
                response.StatusCode  = (int)HttpStatusCode.BadRequest;
                using (StreamWriter sw = new StreamWriter(response.OutputStream)) {
                    sw.WriteLine("<html><body>This is an OpenID Provider endpoint.</body></html>");
                }
                return;
            }

            this.Dispatcher.Invoke((Action) delegate {
                if (!request.IsResponseReady)
                {
                    var authRequest = request as IAuthenticationRequest;
                    if (authRequest != null)
                    {
                        switch (checkidRequestList.SelectedIndex)
                        {
                        case 0:
                            if (authRequest.IsDirectedIdentity)
                            {
                                authRequest.ClaimedIdentifier = new Uri(this.hostedProvider.UserIdentityPageBase, "directedidentity");
                                authRequest.LocalIdentifier   = authRequest.ClaimedIdentifier;
                            }
                            authRequest.IsAuthenticated = true;
                            break;

                        case 1:
                            authRequest.IsAuthenticated = false;
                            break;

                        case 2:
                            IntPtr oldForegroundWindow = NativeMethods.GetForegroundWindow();
                            bool stoleFocus            = NativeMethods.SetForegroundWindow(this);
                            CheckIdWindow.ProcessAuthentication(this.hostedProvider, authRequest);
                            if (stoleFocus)
                            {
                                NativeMethods.SetForegroundWindow(oldForegroundWindow);
                            }
                            break;
                        }
                    }
                }
            });

            this.hostedProvider.Provider.PrepareResponse(request).Send(response);
        }
		/// <summary>
		/// Processes an authentication request by a popup window.
		/// </summary>
		/// <param name="provider">The OpenID Provider host.</param>
		/// <param name="request">The incoming authentication request.</param>
		internal static void ProcessAuthentication(HostedProvider provider, IAuthenticationRequest request) {
			Contract.Requires(provider != null);
			Contract.Requires(request != null);

			var window = new CheckIdWindow(provider, request);
			bool? result = window.ShowDialog();

			// If the user pressed Esc or cancel, just send a negative assertion.
			if (!result.HasValue || !result.Value) {
				request.IsAuthenticated = false;
				return;
			}

			request.IsAuthenticated = window.tabControl1.SelectedItem == window.positiveTab;
			if (request.IsAuthenticated.Value) {
				request.ClaimedIdentifier = window.claimedIdentifierBox.Text;
				request.LocalIdentifier = window.localIdentifierBox.Text;
			}
		}
コード例 #5
0
        /// <summary>
        /// Processes an authentication request by a popup window.
        /// </summary>
        /// <param name="provider">The OpenID Provider host.</param>
        /// <param name="request">The incoming authentication request.</param>
        internal static void ProcessAuthentication(HostedProvider provider, IAuthenticationRequest request)
        {
            Contract.Requires(provider != null);
            Contract.Requires(request != null);

            var  window = new CheckIdWindow(provider, request);
            bool?result = window.ShowDialog();

            // If the user pressed Esc or cancel, just send a negative assertion.
            if (!result.HasValue || !result.Value)
            {
                request.IsAuthenticated = false;
                return;
            }

            request.IsAuthenticated = window.tabControl1.SelectedItem == window.positiveTab;
            if (request.IsAuthenticated.Value)
            {
                request.ClaimedIdentifier = window.claimedIdentifierBox.Text;
                request.LocalIdentifier   = window.localIdentifierBox.Text;
            }
        }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: terry2012/DSV
        /// <summary>
        /// Processes an incoming request at the OpenID Provider endpoint.
        /// </summary>
        /// <param name="requestInfo">The request info.</param>
        /// <param name="response">The response.</param>
        private void ProcessRequest(HttpRequestBase requestInfo, HttpListenerResponse response)
        {
            IRequest request = this.hostedProvider.Provider.GetRequest(requestInfo);

            if (request == null)
            {
                App.Logger.Error("A request came in that did not carry an OpenID message.");
                response.ContentType = "text/html";
                response.StatusCode  = (int)HttpStatusCode.BadRequest;
                using (StreamWriter sw = new StreamWriter(response.OutputStream)) {
                    sw.WriteLine("<html><body>This is an OpenID Provider endpoint.</body></html>");
                }
                return;
            }

            this.Dispatcher.Invoke((Action) delegate {
                if (!request.IsResponseReady)
                {
                    var authRequest = request as IAuthenticationRequest;
                    if (authRequest != null)
                    {
                        switch (this.checkidRequestList.SelectedIndex)
                        {
                        case 0:
                            if (authRequest.IsDirectedIdentity)
                            {
                                string userIdentityPageBase = this.hostedProvider.UserIdentityPageBase.AbsoluteUri;
                                if (this.capitalizedHostName.IsChecked.Value)
                                {
                                    userIdentityPageBase = (this.hostedProvider.UserIdentityPageBase.Scheme + Uri.SchemeDelimiter + this.hostedProvider.UserIdentityPageBase.Authority).ToUpperInvariant() + this.hostedProvider.UserIdentityPageBase.PathAndQuery;
                                }
                                string leafPath = "directedidentity";
                                if (this.directedIdentityTrailingPeriodsCheckbox.IsChecked.Value)
                                {
                                    leafPath += ".";
                                }
                                authRequest.ClaimedIdentifier = Identifier.Parse(userIdentityPageBase + leafPath, true);
                                authRequest.LocalIdentifier   = authRequest.ClaimedIdentifier;
                            }
                            authRequest.IsAuthenticated = true;
                            break;

                        case 1:
                            authRequest.IsAuthenticated = false;
                            break;

                        case 2:
                            IntPtr oldForegroundWindow = NativeMethods.GetForegroundWindow();
                            bool stoleFocus            = NativeMethods.SetForegroundWindow(this);
                            CheckIdWindow.ProcessAuthentication(this.hostedProvider, authRequest);
                            if (stoleFocus)
                            {
                                NativeMethods.SetForegroundWindow(oldForegroundWindow);
                            }
                            break;
                        }
                    }
                }
            });

            this.hostedProvider.Provider.PrepareResponse(request).Send(response);
        }