Example #1
0
        /// <summary>
        /// Gets the full URL that carries an OpenID message, even if it exceeds the normal maximum size of a URL,
        /// for purposes of sending to an AJAX component running in the browser.
        /// </summary>
        /// <param name="request">The authentication request.</param>
        /// <param name="immediate"><c>true</c>to create a checkid_immediate request;
        /// <c>false</c> to create a checkid_setup request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The absolute URL that carries the entire OpenID message.
        /// </returns>
        private async Task <Uri> GetRedirectUrlAsync(IAuthenticationRequest request, bool immediate, CancellationToken cancellationToken)
        {
            Requires.NotNull(request, "request");

            request.Mode = immediate ? AuthenticationRequestMode.Immediate : AuthenticationRequestMode.Setup;
            var response = await request.GetRedirectingResponseAsync(cancellationToken);

            return(response.GetDirectUriRequest());
        }
        /// <summary>
        /// Immediately sends a redirect response to the browser to initiate an authentication request.
        /// </summary>
        /// <param name="authenticationRequest">The authentication request to send via redirect.</param>
        /// <param name="context">The context.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// A task that completes with the asynchronous operation.
        /// </returns>
        public static async Task RedirectToProviderAsync(this IAuthenticationRequest authenticationRequest, HttpContextBase context = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Requires.NotNull(authenticationRequest, "authenticationRequest");
            Verify.Operation(context != null || HttpContext.Current != null, MessagingStrings.HttpContextRequired);

            context = context ?? new HttpContextWrapper(HttpContext.Current);
            var response = await authenticationRequest.GetRedirectingResponseAsync(cancellationToken);

            await response.SendAsync(context, cancellationToken);
        }
Example #3
0
		/// <summary>
		/// Gets the <c>window.open</c> javascript snippet to use to open a popup window
		/// compliant with the UI extension.
		/// </summary>
		/// <param name="relyingParty">The relying party.</param>
		/// <param name="request">The authentication request to place in the window.</param>
		/// <param name="windowName">The name to assign to the popup window.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <returns>
		/// A string starting with 'window.open' and forming just that one method call.
		/// </returns>
		internal static async Task<string> GetWindowPopupScriptAsync(OpenIdRelyingParty relyingParty, IAuthenticationRequest request, string windowName, CancellationToken cancellationToken) {
			Requires.NotNull(relyingParty, "relyingParty");
			Requires.NotNull(request, "request");
			Requires.NotNullOrEmpty(windowName, "windowName");

			var response = await request.GetRedirectingResponseAsync(cancellationToken);
			Uri popupUrl = response.GetDirectUriRequest();

			return string.Format(
				CultureInfo.InvariantCulture,
				"(window.showModalDialog ? window.showModalDialog({0}, {1}, 'status:0;resizable:1;scroll:1;center:1;dialogWidth:{2}px; dialogHeight:{3}') : window.open({0}, {1}, 'status=0,toolbar=0,location=1,resizable=1,scrollbars=1,left=' + ((screen.width - {2}) / 2) + ',top=' + ((screen.height - {3}) / 2) + ',width={2},height={3}'));",
				MessagingUtilities.GetSafeJavascriptValue(popupUrl.AbsoluteUri),
				MessagingUtilities.GetSafeJavascriptValue(windowName),
				OpenId.Extensions.UI.UIUtilities.PopupWidth,
				OpenId.Extensions.UI.UIUtilities.PopupHeight);
		}
Example #4
0
        /// <summary>
        /// Gets the <c>window.open</c> javascript snippet to use to open a popup window
        /// compliant with the UI extension.
        /// </summary>
        /// <param name="relyingParty">The relying party.</param>
        /// <param name="request">The authentication request to place in the window.</param>
        /// <param name="windowName">The name to assign to the popup window.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// A string starting with 'window.open' and forming just that one method call.
        /// </returns>
        internal static async Task <string> GetWindowPopupScriptAsync(OpenIdRelyingParty relyingParty, IAuthenticationRequest request, string windowName, CancellationToken cancellationToken)
        {
            Requires.NotNull(relyingParty, "relyingParty");
            Requires.NotNull(request, "request");
            Requires.NotNullOrEmpty(windowName, "windowName");

            var response = await request.GetRedirectingResponseAsync(cancellationToken);

            Uri popupUrl = response.GetDirectUriRequest();

            return(string.Format(
                       CultureInfo.InvariantCulture,
                       "(window.showModalDialog ? window.showModalDialog({0}, {1}, 'status:0;resizable:1;scroll:1;center:1;dialogWidth:{2}px; dialogHeight:{3}') : window.open({0}, {1}, 'status=0,toolbar=0,location=1,resizable=1,scrollbars=1,left=' + ((screen.width - {2}) / 2) + ',top=' + ((screen.height - {3}) / 2) + ',width={2},height={3}'));",
                       MessagingUtilities.GetSafeJavascriptValue(popupUrl.AbsoluteUri),
                       MessagingUtilities.GetSafeJavascriptValue(windowName),
                       OpenId.Extensions.UI.UIUtilities.PopupWidth,
                       OpenId.Extensions.UI.UIUtilities.PopupHeight));
        }
		/// <summary>
		/// Gets the full URL that carries an OpenID message, even if it exceeds the normal maximum size of a URL,
		/// for purposes of sending to an AJAX component running in the browser.
		/// </summary>
		/// <param name="request">The authentication request.</param>
		/// <param name="immediate"><c>true</c>to create a checkid_immediate request;
		/// <c>false</c> to create a checkid_setup request.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		/// <returns>
		/// The absolute URL that carries the entire OpenID message.
		/// </returns>
		private async Task<Uri> GetRedirectUrlAsync(IAuthenticationRequest request, bool immediate, CancellationToken cancellationToken) {
			Requires.NotNull(request, "request");

			request.Mode = immediate ? AuthenticationRequestMode.Immediate : AuthenticationRequestMode.Setup;
			var response = await request.GetRedirectingResponseAsync(cancellationToken);
			return response.GetDirectUriRequest();
		}