diff options
6 files changed, 50 insertions, 15 deletions
diff --git a/projecttemplates/MvcRelyingParty/Code/OpenIdRelyingPartyService.cs b/projecttemplates/MvcRelyingParty/Code/OpenIdRelyingPartyService.cs index bc57819..4501f52 100644 --- a/projecttemplates/MvcRelyingParty/Code/OpenIdRelyingPartyService.cs +++ b/projecttemplates/MvcRelyingParty/Code/OpenIdRelyingPartyService.cs @@ -18,6 +18,8 @@ ActionResult AjaxDiscovery(Identifier userSuppliedIdentifier, Realm realm, Uri returnTo, Uri privacyPolicy); + string PreloadDiscoveryResults(Realm realm, Uri returnTo, Uri privacyPolicy, params Identifier[] identifiers); + ActionResult ProcessAjaxOpenIdResponse(); IAuthenticationResponse GetResponse(); @@ -86,6 +88,11 @@ this.CreateRequests(userSuppliedIdentifier, realm, returnTo, privacyPolicy)).AsActionResult(); } + public string PreloadDiscoveryResults(Realm realm, Uri returnTo, Uri privacyPolicy, params Identifier[] identifiers) { + return relyingParty.AsAjaxPreloadedDiscoveryResult( + identifiers.Select(id => this.CreateRequests(id, realm, returnTo, privacyPolicy)).Flatten()); + } + public ActionResult ProcessAjaxOpenIdResponse() { return relyingParty.ProcessResponseFromPopup().AsActionResult(); } diff --git a/projecttemplates/MvcRelyingParty/Controllers/AuthController.cs b/projecttemplates/MvcRelyingParty/Controllers/AuthController.cs index 20dd8fa..be5e4b1 100644 --- a/projecttemplates/MvcRelyingParty/Controllers/AuthController.cs +++ b/projecttemplates/MvcRelyingParty/Controllers/AuthController.cs @@ -80,6 +80,7 @@ namespace MvcRelyingParty.Controllers { /// </summary> /// <returns>The action result.</returns> public ActionResult LogOn() { + this.PreloadDiscoveryResults(); return View(); } @@ -88,6 +89,7 @@ namespace MvcRelyingParty.Controllers { /// </summary> /// <returns>The action result.</returns> public ActionResult LogOnPopUp() { + this.PreloadDiscoveryResults(); return View(); } @@ -207,5 +209,17 @@ namespace MvcRelyingParty.Controllers { this.FormsAuth.SignOut(); return RedirectToAction("Index", "Home"); } + + /// <summary> + /// Preloads discovery results for the OP buttons we display on the selector in the ViewData. + /// </summary> + private void PreloadDiscoveryResults() { + this.ViewData["PreloadedDiscoveryResults"] = this.RelyingParty.PreloadDiscoveryResults( + Realm.AutoDetect, + Url.ActionFull("PopUpReturnTo"), + this.PrivacyPolicyUrl, + "https://me.yahoo.com/", + "https://www.google.com/accounts/o8/id"); + } } } diff --git a/projecttemplates/MvcRelyingParty/Views/Auth/LogOnScripts.ascx b/projecttemplates/MvcRelyingParty/Views/Auth/LogOnScripts.ascx index 64c4fae..0ebc38b 100644 --- a/projecttemplates/MvcRelyingParty/Views/Auth/LogOnScripts.ascx +++ b/projecttemplates/MvcRelyingParty/Views/Auth/LogOnScripts.ascx @@ -3,4 +3,9 @@ <script type="text/javascript" src='<%= Url.Content("~/Scripts/MicrosoftAjax.js") %>'></script> <script type="text/javascript" src='<%= Url.Content("~/Scripts/MicrosoftMvcAjax.js") %>'></script> <script type="text/javascript" src='<%= Url.Content("~/Scripts/jquery.cookie.js") %>'></script> -<%= Html.OpenIdSelectorScripts(this.Page)%> +<% + var options = new OpenIdAjaxOptions { + PreloadedDiscoveryResults = (string)this.ViewData["PreloadedDiscoveryResults"], + }; +%> +<%= Html.OpenIdSelectorScripts(this.Page, null, options)%> diff --git a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs index 8ae228d..7367c01 100644 --- a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs +++ b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs @@ -176,6 +176,20 @@ namespace DotNetOpenAuth.Messaging { } /// <summary> + /// Flattens the specified sequence of sequences. + /// </summary> + /// <typeparam name="T">The type of element contained in the sequence.</typeparam> + /// <param name="sequence">The sequence of sequences to flatten.</param> + /// <returns>A sequence of the contained items.</returns> + public static IEnumerable<T> Flatten<T>(this IEnumerable<IEnumerable<T>> sequence) { + foreach (IEnumerable<T> subsequence in sequence) { + foreach (T item in subsequence) { + yield return item; + } + } + } + + /// <summary> /// Sends a multipart HTTP POST request (useful for posting files) but doesn't call GetResponse on it. /// </summary> /// <param name="request">The HTTP request.</param> @@ -473,20 +487,6 @@ namespace DotNetOpenAuth.Messaging { } /// <summary> - /// Flattens the specified sequence of sequences. - /// </summary> - /// <typeparam name="T">The type of element contained in the sequence.</typeparam> - /// <param name="sequence">The sequence of sequences to flatten.</param> - /// <returns>A sequence of the contained items.</returns> - internal static IEnumerable<T> Flatten<T>(this IEnumerable<IEnumerable<T>> sequence) { - foreach (IEnumerable<T> subsequence in sequence) { - foreach (T item in subsequence) { - yield return item; - } - } - } - - /// <summary> /// Tests whether two arrays are equal in contents and ordering. /// </summary> /// <typeparam name="T">The type of elements in the arrays.</typeparam> diff --git a/src/DotNetOpenAuth/Mvc/OpenIdAjaxOptions.cs b/src/DotNetOpenAuth/Mvc/OpenIdAjaxOptions.cs index a412ef2..9956966 100644 --- a/src/DotNetOpenAuth/Mvc/OpenIdAjaxOptions.cs +++ b/src/DotNetOpenAuth/Mvc/OpenIdAjaxOptions.cs @@ -41,6 +41,11 @@ namespace DotNetOpenAuth.Mvc { public int FormIndex { get; set; } /// <summary> + /// Gets or sets the preloaded discovery results. + /// </summary> + public string PreloadedDiscoveryResults { get; set; } + + /// <summary> /// Gets or sets a value indicating whether to print diagnostic trace messages in the browser. /// </summary> public bool ShowDiagnosticTrace { get; set; } diff --git a/src/DotNetOpenAuth/Mvc/OpenIdHelper.cs b/src/DotNetOpenAuth/Mvc/OpenIdHelper.cs index 55af17d..03d2a07 100644 --- a/src/DotNetOpenAuth/Mvc/OpenIdHelper.cs +++ b/src/DotNetOpenAuth/Mvc/OpenIdHelper.cs @@ -124,6 +124,10 @@ window.openid_trace = {1}; // causes lots of messages"; OpenIdRelyingPartyAjaxControlBase.MaxPositiveAssertionLifetimeJsName, assertionLifetimeInMilliseconds.ToString(CultureInfo.InvariantCulture)); + if (additionalOptions.PreloadedDiscoveryResults != null) { + blockBuilder.WriteLine(additionalOptions.PreloadedDiscoveryResults); + } + string discoverUrl = VirtualPathUtility.AppendTrailingSlash(HttpContext.Current.Request.ApplicationPath) + html.RouteCollection["OpenIdDiscover"].GetVirtualPath(html.ViewContext.RequestContext, new RouteValueDictionary(new { identifier = "xxx" })).VirtualPath; string blockFormat = @" {0} = function (argument, resultFunction, errorCallback) {{ jQuery.ajax({{ |