diff options
6 files changed, 138 insertions, 137 deletions
diff --git a/projecttemplates/WebFormsRelyingParty/Admin/Default.aspx.cs b/projecttemplates/WebFormsRelyingParty/Admin/Default.aspx.cs index 9e45e45..cc9abf1 100644 --- a/projecttemplates/WebFormsRelyingParty/Admin/Default.aspx.cs +++ b/projecttemplates/WebFormsRelyingParty/Admin/Default.aspx.cs @@ -17,8 +17,8 @@ namespace WebFormsRelyingParty.Admin { public partial class Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { - usersRepeater.DataSource = Global.DataContext.User.Include("AuthenticationTokens"); - usersRepeater.DataBind(); + this.usersRepeater.DataSource = Global.DataContext.User.Include("AuthenticationTokens"); + this.usersRepeater.DataBind(); } } } diff --git a/projecttemplates/WebFormsRelyingParty/LoginFrame.aspx.cs b/projecttemplates/WebFormsRelyingParty/LoginFrame.aspx.cs index a04abcf..66ba529 100644 --- a/projecttemplates/WebFormsRelyingParty/LoginFrame.aspx.cs +++ b/projecttemplates/WebFormsRelyingParty/LoginFrame.aspx.cs @@ -1,26 +1,27 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Web; -using System.Web.Security; -using System.Web.UI; -using System.Web.UI.WebControls; -using DotNetOpenAuth.InfoCard; -using DotNetOpenAuth.Messaging; -using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration; -using DotNetOpenAuth.OpenId.RelyingParty; +namespace WebFormsRelyingParty { + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Linq; + using System.Web; + using System.Web.Security; + using System.Web.UI; + using System.Web.UI.WebControls; + using DotNetOpenAuth.InfoCard; + using DotNetOpenAuth.Messaging; + using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration; + using DotNetOpenAuth.OpenId.RelyingParty; -namespace WebFormsRelyingParty { public partial class LoginFrame : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Because this page can appear as an iframe in a popup of another page, // we need to record which page the hosting page is in order to redirect back // to it after login is complete. - this.ClientScript.RegisterOnSubmitStatement(this.GetType(), "getTopWindowUrl", @" -document.getElementById('topWindowUrl').value = window.parent.location.href; -"); + this.ClientScript.RegisterOnSubmitStatement( + this.GetType(), + "getTopWindowUrl", + "document.getElementById('topWindowUrl').value = window.parent.location.href;"); } } @@ -32,6 +33,18 @@ document.getElementById('topWindowUrl').value = window.parent.location.href; this.LoginUser(AuthenticationToken.SynthesizeClaimedIdentifierFromInfoCard(e.Token.UniqueId), e.Token.SiteSpecificId, null); } + protected void openIdButtonPanel_Failed(object sender, OpenIdEventArgs e) { + if (e.Response.Exception != null) { + errorMessageLabel.Text = e.Response.Exception.Message; + } + this.errorPanel.Visible = true; + } + + protected void openIdButtonPanel_TokenProcessingError(object sender, TokenProcessingErrorEventArgs e) { + this.errorMessageLabel.Text = e.Exception.Message; + this.errorPanel.Visible = true; + } + private void LoginUser(string claimedIdentifier, string friendlyIdentifier, ClaimsResponse claims) { // Create an account for this user if we don't already have one. AuthenticationToken openidToken = Global.DataContext.AuthenticationToken.FirstOrDefault(token => token.ClaimedIdentifier == claimedIdentifier); @@ -65,11 +78,11 @@ document.getElementById('topWindowUrl').value = window.parent.location.href; bool persistentCookie = false; if (string.IsNullOrEmpty(this.Request.QueryString["ReturnUrl"])) { FormsAuthentication.SetAuthCookie(openidToken.ClaimedIdentifier, persistentCookie); - if (!string.IsNullOrEmpty(topWindowUrl.Value)) { - Uri topWindowUri = new Uri(topWindowUrl.Value); + if (!string.IsNullOrEmpty(this.topWindowUrl.Value)) { + Uri topWindowUri = new Uri(this.topWindowUrl.Value); string returnUrl = HttpUtility.ParseQueryString(topWindowUri.Query)["ReturnUrl"]; if (string.IsNullOrEmpty(returnUrl)) { - Response.Redirect(topWindowUrl.Value); + Response.Redirect(this.topWindowUrl.Value); } else { Response.Redirect(returnUrl); } @@ -81,17 +94,5 @@ document.getElementById('topWindowUrl').value = window.parent.location.href; FormsAuthentication.RedirectFromLoginPage(openidToken.ClaimedIdentifier, persistentCookie); } } - - protected void openIdButtonPanel_Failed(object sender, OpenIdEventArgs e) { - if (e.Response.Exception != null) { - errorMessageLabel.Text = e.Response.Exception.Message; - } - errorPanel.Visible = true; - } - - protected void openIdButtonPanel_TokenProcessingError(object sender, TokenProcessingErrorEventArgs e) { - errorMessageLabel.Text = e.Exception.Message; - errorPanel.Visible = true; - } } } diff --git a/src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs b/src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs index 0205759..9159639 100644 --- a/src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs +++ b/src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs @@ -629,9 +629,8 @@ namespace DotNetOpenAuth.InfoCard { } /// <summary> - /// Creates the info card selector <object> HTML tag. + /// Adds the javascript that adds the info card selector <object> HTML tag to the page. /// </summary> - /// <returns>A control that renders to the <object> tag.</returns> [Pure] private void RegisterInfoCardSelectorObjectScript() { string scriptFormat = @"{{ diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdButtonPanel.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdButtonPanel.cs index 1e72dd6..cb2c9ea 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdButtonPanel.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdButtonPanel.cs @@ -166,10 +166,10 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { base.CreateChildControls(); this.infoCardSelector = new InfoCardSelector(); - infoCardSelector.ClaimsRequested.Add(new ClaimType { Name = ClaimTypes.PPID }); - infoCardSelector.ImageSize = InfoCardImageSize.Size60x42; - infoCardSelector.ReceivedToken += infoCardSelector_ReceivedToken; - infoCardSelector.TokenProcessingError += infoCardSelector_TokenProcessingError; + this.infoCardSelector.ClaimsRequested.Add(new ClaimType { Name = ClaimTypes.PPID }); + this.infoCardSelector.ImageSize = InfoCardImageSize.Size60x42; + this.infoCardSelector.ReceivedToken += this.InfoCardSelector_ReceivedToken; + this.infoCardSelector.TokenProcessingError += this.InfoCardSelector_TokenProcessingError; this.Controls.Add(this.infoCardSelector); this.textBox = new OpenIdAjaxTextBox(); @@ -211,17 +211,18 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { this.Page.ClientScript.RegisterClientScriptResource(typeof(OpenIdButtonPanel), EmbeddedScriptResourceName); // Provide javascript with a way to post the login assertion. - const string postLoginAssertionMethodName = "postLoginAssertion"; - const string positiveAssertionParameterName = "positiveAssertion"; - string script = string.Format( - CultureInfo.InvariantCulture, -@"window.{2} = function({0}) {{ + const string PostLoginAssertionMethodName = "postLoginAssertion"; + const string PositiveAssertionParameterName = "positiveAssertion"; + const string ScriptFormat = @"window.{2} = function({0}) {{ $('#{3}')[0].setAttribute('value', {0}); {1}; -}};", - positiveAssertionParameterName, +}};"; + string script = string.Format( + CultureInfo.InvariantCulture, + ScriptFormat, + PositiveAssertionParameterName, this.Page.ClientScript.GetPostBackEventReference(this, null, false), - postLoginAssertionMethodName, + PostLoginAssertionMethodName, this.positiveAssertionField.ClientID); this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Postback", script, true); @@ -275,7 +276,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderBeginTag(HtmlTextWriterTag.Div); - infoCardSelector.RenderControl(writer); + this.infoCardSelector.RenderControl(writer); writer.RenderEndTag(); // </div> @@ -334,7 +335,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="DotNetOpenAuth.InfoCard.ReceivedTokenEventArgs"/> instance containing the event data.</param> - private void infoCardSelector_ReceivedToken(object sender, ReceivedTokenEventArgs e) { + private void InfoCardSelector_ReceivedToken(object sender, ReceivedTokenEventArgs e) { this.Page.Response.SetCookie(new HttpCookie("openid_identifier", "infocard") { Path = this.Page.Request.ApplicationPath, }); @@ -346,7 +347,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="DotNetOpenAuth.InfoCard.TokenProcessingErrorEventArgs"/> instance containing the event data.</param> - private void infoCardSelector_TokenProcessingError(object sender, TokenProcessingErrorEventArgs e) { + private void InfoCardSelector_TokenProcessingError(object sender, TokenProcessingErrorEventArgs e) { this.OnTokenProcessingError(e); } } @@ -357,7 +358,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { [TypeConverter(typeof(IdentifierConverter))] public Identifier OPIdentifier { get; set; } - + public string Image { get; set; } } } diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingPartyAjaxControlBase.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingPartyAjaxControlBase.cs index b7b6d85..c546901 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingPartyAjaxControlBase.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingPartyAjaxControlBase.cs @@ -260,7 +260,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { Logger.OpenId.InfoFormat("AJAX discovery on {0} requested.", userSuppliedIdentifier); this.Identifier = userSuppliedIdentifier; - this.discoveryResult = SerializeDiscoveryAsJson(this.Identifier); + this.discoveryResult = this.SerializeDiscoveryAsJson(this.Identifier); } /// <summary> @@ -278,96 +278,12 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// </summary> /// <param name="identifiers">The identifiers to perform discovery on.</param> protected void PreloadDiscovery(IEnumerable<Identifier> identifiers) { - string discoveryResults = SerializeDiscoveryAsJson(identifiers); + string discoveryResults = this.SerializeDiscoveryAsJson(identifiers); string script = "window.dnoa_internal.loadPreloadedDiscoveryResults(" + discoveryResults + ");"; this.Page.ClientScript.RegisterClientScriptBlock(typeof(OpenIdRelyingPartyAjaxControlBase), this.ClientID, script, true); } /// <summary> - /// Serializes the discovery of multiple identifiers as a JSON object. - /// </summary> - /// <param name="identifiers">The identifiers to perform discovery on and create requests for.</param> - /// <returns>The serialized JSON object.</returns> - private string SerializeDiscoveryAsJson(IEnumerable<Identifier> identifiers) { - ErrorUtilities.VerifyArgumentNotNull(identifiers, "identifiers"); - - // We prepare a JSON object with this interface: - // Array discoveryWrappers; - // Where each element in the above array has this interface: - // class discoveryWrapper { - // string userSuppliedIdentifier; - // jsonResponse discoveryResult; // contains result of call to SerializeDiscoveryAsJson(Identifier) - // } - - StringBuilder discoveryResultBuilder = new StringBuilder(); - discoveryResultBuilder.Append("["); - foreach(var identifier in identifiers) { // TODO: parallelize discovery on these identifiers - discoveryResultBuilder.Append("{"); - discoveryResultBuilder.AppendFormat("userSuppliedIdentifier: {0},", MessagingUtilities.GetSafeJavascriptValue(identifier)); - discoveryResultBuilder.AppendFormat("discoveryResult: {0}", SerializeDiscoveryAsJson(identifier)); - discoveryResultBuilder.Append("},"); - } - - discoveryResultBuilder.Length -= 1; // trim last comma - discoveryResultBuilder.Append("]"); - return discoveryResultBuilder.ToString(); - } - - /// <summary> - /// Serializes the results of discovery and the created auth requests as a JSON object - /// for the user agent to initiate. - /// </summary> - /// <param name="identifier">The identifier to perform discovery on.</param> - /// <returns>The JSON string.</returns> - private string SerializeDiscoveryAsJson(Identifier identifier) { - ErrorUtilities.VerifyArgumentNotNull(identifier, "identifier"); - - // We prepare a JSON object with this interface: - // class jsonResponse { - // string claimedIdentifier; - // Array requests; // never null - // string error; // null if no error - // } - // Each element in the requests array looks like this: - // class jsonAuthRequest { - // string endpoint; // URL to the OP endpoint - // string immediate; // URL to initiate an immediate request - // string setup; // URL to initiate a setup request. - // } - StringBuilder discoveryResultBuilder = new StringBuilder(); - discoveryResultBuilder.Append("{"); - try { - IEnumerable<IAuthenticationRequest> requests = this.CreateRequests(identifier).CacheGeneratedResults(); - if (requests.Any()) { - discoveryResultBuilder.AppendFormat("claimedIdentifier: {0},", MessagingUtilities.GetSafeJavascriptValue(requests.First().ClaimedIdentifier)); - discoveryResultBuilder.Append("requests: ["); - foreach (IAuthenticationRequest request in requests) { - discoveryResultBuilder.Append("{"); - discoveryResultBuilder.AppendFormat("endpoint: {0},", MessagingUtilities.GetSafeJavascriptValue(request.Provider.Uri.AbsoluteUri)); - request.Mode = AuthenticationRequestMode.Immediate; - OutgoingWebResponse response = request.RedirectingResponse; - discoveryResultBuilder.AppendFormat("immediate: {0},", MessagingUtilities.GetSafeJavascriptValue(response.GetDirectUriRequest(this.RelyingParty.Channel).AbsoluteUri)); - request.Mode = AuthenticationRequestMode.Setup; - response = request.RedirectingResponse; - discoveryResultBuilder.AppendFormat("setup: {0}", MessagingUtilities.GetSafeJavascriptValue(response.GetDirectUriRequest(this.RelyingParty.Channel).AbsoluteUri)); - discoveryResultBuilder.Append("},"); - } - discoveryResultBuilder.Length -= 1; // trim off last comma - discoveryResultBuilder.Append("]"); - } else { - discoveryResultBuilder.Append("requests: [],"); - discoveryResultBuilder.AppendFormat("error: {0}", MessagingUtilities.GetSafeJavascriptValue(OpenIdStrings.OpenIdEndpointNotFound)); - } - } catch (ProtocolException ex) { - discoveryResultBuilder.Append("requests: [],"); - discoveryResultBuilder.AppendFormat("error: {0}", MessagingUtilities.GetSafeJavascriptValue(ex.Message)); - } - - discoveryResultBuilder.Append("}"); - return discoveryResultBuilder.ToString(); - } - - /// <summary> /// Fires the <see cref="UnconfirmedPositiveAssertion"/> event. /// </summary> protected virtual void OnUnconfirmedPositiveAssertion() { @@ -514,6 +430,89 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { } /// <summary> + /// Serializes the discovery of multiple identifiers as a JSON object. + /// </summary> + /// <param name="identifiers">The identifiers to perform discovery on and create requests for.</param> + /// <returns>The serialized JSON object.</returns> + private string SerializeDiscoveryAsJson(IEnumerable<Identifier> identifiers) { + ErrorUtilities.VerifyArgumentNotNull(identifiers, "identifiers"); + + // We prepare a JSON object with this interface: + // Array discoveryWrappers; + // Where each element in the above array has this interface: + // class discoveryWrapper { + // string userSuppliedIdentifier; + // jsonResponse discoveryResult; // contains result of call to SerializeDiscoveryAsJson(Identifier) + // } + StringBuilder discoveryResultBuilder = new StringBuilder(); + discoveryResultBuilder.Append("["); + foreach (var identifier in identifiers) { // TODO: parallelize discovery on these identifiers + discoveryResultBuilder.Append("{"); + discoveryResultBuilder.AppendFormat("userSuppliedIdentifier: {0},", MessagingUtilities.GetSafeJavascriptValue(identifier)); + discoveryResultBuilder.AppendFormat("discoveryResult: {0}", this.SerializeDiscoveryAsJson(identifier)); + discoveryResultBuilder.Append("},"); + } + + discoveryResultBuilder.Length -= 1; // trim last comma + discoveryResultBuilder.Append("]"); + return discoveryResultBuilder.ToString(); + } + + /// <summary> + /// Serializes the results of discovery and the created auth requests as a JSON object + /// for the user agent to initiate. + /// </summary> + /// <param name="identifier">The identifier to perform discovery on.</param> + /// <returns>The JSON string.</returns> + private string SerializeDiscoveryAsJson(Identifier identifier) { + ErrorUtilities.VerifyArgumentNotNull(identifier, "identifier"); + + // We prepare a JSON object with this interface: + // class jsonResponse { + // string claimedIdentifier; + // Array requests; // never null + // string error; // null if no error + // } + // Each element in the requests array looks like this: + // class jsonAuthRequest { + // string endpoint; // URL to the OP endpoint + // string immediate; // URL to initiate an immediate request + // string setup; // URL to initiate a setup request. + // } + StringBuilder discoveryResultBuilder = new StringBuilder(); + discoveryResultBuilder.Append("{"); + try { + IEnumerable<IAuthenticationRequest> requests = this.CreateRequests(identifier).CacheGeneratedResults(); + if (requests.Any()) { + discoveryResultBuilder.AppendFormat("claimedIdentifier: {0},", MessagingUtilities.GetSafeJavascriptValue(requests.First().ClaimedIdentifier)); + discoveryResultBuilder.Append("requests: ["); + foreach (IAuthenticationRequest request in requests) { + discoveryResultBuilder.Append("{"); + discoveryResultBuilder.AppendFormat("endpoint: {0},", MessagingUtilities.GetSafeJavascriptValue(request.Provider.Uri.AbsoluteUri)); + request.Mode = AuthenticationRequestMode.Immediate; + OutgoingWebResponse response = request.RedirectingResponse; + discoveryResultBuilder.AppendFormat("immediate: {0},", MessagingUtilities.GetSafeJavascriptValue(response.GetDirectUriRequest(this.RelyingParty.Channel).AbsoluteUri)); + request.Mode = AuthenticationRequestMode.Setup; + response = request.RedirectingResponse; + discoveryResultBuilder.AppendFormat("setup: {0}", MessagingUtilities.GetSafeJavascriptValue(response.GetDirectUriRequest(this.RelyingParty.Channel).AbsoluteUri)); + discoveryResultBuilder.Append("},"); + } + discoveryResultBuilder.Length -= 1; // trim off last comma + discoveryResultBuilder.Append("]"); + } else { + discoveryResultBuilder.Append("requests: [],"); + discoveryResultBuilder.AppendFormat("error: {0}", MessagingUtilities.GetSafeJavascriptValue(OpenIdStrings.OpenIdEndpointNotFound)); + } + } catch (ProtocolException ex) { + discoveryResultBuilder.Append("requests: [],"); + discoveryResultBuilder.AppendFormat("error: {0}", MessagingUtilities.GetSafeJavascriptValue(ex.Message)); + } + + discoveryResultBuilder.Append("}"); + return discoveryResultBuilder.ToString(); + } + + /// <summary> /// Creates the authentication requests for a given user-supplied Identifier. /// </summary> /// <param name="requests">The authentication requests to prepare.</param> diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs index 96e4186..8337823 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs @@ -545,6 +545,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// <summary> /// Creates the authentication requests for a given user-supplied Identifier. /// </summary> + /// <param name="identifier">The identifier to create a request for.</param> /// <returns> /// A sequence of authentication requests, any one of which may be /// used to determine the user's control of the <see cref="IAuthenticationRequest.ClaimedIdentifier"/>. |