summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.cs')
-rw-r--r--src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.cs110
1 files changed, 86 insertions, 24 deletions
diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.cs
index e93383d..b7a54eb 100644
--- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.cs
+++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.cs
@@ -81,11 +81,6 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
private HiddenField positiveAssertionField;
/// <summary>
- /// A field to store the value to set on the <see cref="textBox"/> control after it's created.
- /// </summary>
- private bool downloadYuiLibrary = OpenIdAjaxTextBox.DownloadYahooUILibraryDefault;
-
- /// <summary>
/// Initializes a new instance of the <see cref="OpenIdSelector"/> class.
/// </summary>
public OpenIdSelector() {
@@ -102,6 +97,50 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
public event EventHandler<TokenProcessingErrorEventArgs> TokenProcessingError;
/// <summary>
+ /// Gets the text box where applicable.
+ /// </summary>
+ public OpenIdAjaxTextBox TextBox {
+ get {
+ this.EnsureChildControlsAreCreatedSafe();
+ return this.textBox;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the maximum number of OpenID Providers to simultaneously try to authenticate with.
+ /// </summary>
+ [Browsable(true), DefaultValue(OpenIdAjaxTextBox.ThrottleDefault), Category(BehaviorCategory)]
+ [Description("The maximum number of OpenID Providers to simultaneously try to authenticate with.")]
+ public int Throttle {
+ get {
+ this.EnsureChildControlsAreCreatedSafe();
+ return this.textBox.Throttle;
+ }
+
+ set {
+ this.EnsureChildControlsAreCreatedSafe();
+ this.textBox.Throttle = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the time duration for the AJAX control to wait for an OP to respond before reporting failure to the user.
+ /// </summary>
+ [Browsable(true), DefaultValue(typeof(TimeSpan), "00:00:08"), Category(BehaviorCategory)]
+ [Description("The time duration for the AJAX control to wait for an OP to respond before reporting failure to the user.")]
+ public TimeSpan Timeout {
+ get {
+ this.EnsureChildControlsAreCreatedSafe();
+ return this.textBox.Timeout;
+ }
+
+ set {
+ this.EnsureChildControlsAreCreatedSafe();
+ this.textBox.Timeout = value;
+ }
+ }
+
+ /// <summary>
/// Gets or sets the tool tip text that appears on the green checkmark when authentication succeeds.
/// </summary>
[Bindable(true), DefaultValue(AuthenticatedAsToolTipDefault), Localizable(true), Category(AppearanceCategory)]
@@ -126,19 +165,13 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
[Description("Whether a split button will be used for the \"log in\" when the user provides an identifier that delegates to more than one Provider.")]
public bool DownloadYahooUILibrary {
get {
- return this.textBox != null ? this.textBox.DownloadYahooUILibrary : this.downloadYuiLibrary;
+ this.EnsureChildControlsAreCreatedSafe();
+ return this.textBox.DownloadYahooUILibrary;
}
set {
- // We don't just call EnsureChildControls() and then set the property on
- // this.textBox itself because (apparently) setting this property in the ASPX
- // page and thus calling this EnsureID() via EnsureChildControls() this early
- // results in no ID.
- if (this.textBox != null) {
- this.textBox.DownloadYahooUILibrary = value;
- } else {
- this.downloadYuiLibrary = value;
- }
+ this.EnsureChildControlsAreCreatedSafe();
+ this.textBox.DownloadYahooUILibrary = value;
}
}
@@ -207,10 +240,37 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
/// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
/// </summary>
protected override void CreateChildControls() {
+ this.EnsureChildControlsAreCreatedSafe();
+
base.CreateChildControls();
+
+ // Now do the ID specific work.
this.EnsureID();
ErrorUtilities.VerifyInternal(!string.IsNullOrEmpty(this.UniqueID), "Control.EnsureID() failed to give us a unique ID. Try setting an ID on the OpenIdSelector control. But please also file this bug with the project owners.");
+ this.Controls.Add(this.textBox);
+
+ this.positiveAssertionField.ID = this.ID + AuthDataFormKeySuffix;
+ this.Controls.Add(this.positiveAssertionField);
+ }
+
+ /// <summary>
+ /// Ensures that the child controls have been built, but doesn't set control
+ /// properties that require executing <see cref="Control.EnsureID"/> in order to avoid
+ /// certain initialization order problems.
+ /// </summary>
+ /// <remarks>
+ /// We don't just call EnsureChildControls() and then set the property on
+ /// this.textBox itself because (apparently) setting this property in the ASPX
+ /// page and thus calling this EnsureID() via EnsureChildControls() this early
+ /// results in no ID.
+ /// </remarks>
+ protected virtual void EnsureChildControlsAreCreatedSafe() {
+ // If we've already created the child controls, this method is a no-op.
+ if (this.textBox != null) {
+ return;
+ }
+
var selectorButton = this.Buttons.OfType<SelectorInfoCardButton>().FirstOrDefault();
if (selectorButton != null) {
var selector = selectorButton.InfoCardSelector;
@@ -225,12 +285,8 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
this.textBox.ID = "openid_identifier";
this.textBox.HookFormSubmit = false;
this.textBox.ShowLogOnPostBackButton = true;
- this.textBox.DownloadYahooUILibrary = this.downloadYuiLibrary;
- this.Controls.Add(this.textBox);
this.positiveAssertionField = new HiddenField();
- this.positiveAssertionField.ID = this.ID + AuthDataFormKeySuffix;
- this.Controls.Add(this.positiveAssertionField);
}
/// <summary>
@@ -254,11 +310,16 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
this.EnsureValidButtons();
var css = new HtmlLink();
- css.Href = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), EmbeddedStylesheetResourceName);
- css.Attributes["rel"] = "stylesheet";
- css.Attributes["type"] = "text/css";
- ErrorUtilities.VerifyHost(this.Page.Header != null, OpenIdStrings.HeadTagMustIncludeRunatServer);
- this.Page.Header.Controls.AddAt(0, css); // insert at top so host page can override
+ try {
+ css.Href = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), EmbeddedStylesheetResourceName);
+ css.Attributes["rel"] = "stylesheet";
+ css.Attributes["type"] = "text/css";
+ ErrorUtilities.VerifyHost(this.Page.Header != null, OpenIdStrings.HeadTagMustIncludeRunatServer);
+ this.Page.Header.Controls.AddAt(0, css); // insert at top so host page can override
+ } catch {
+ css.Dispose();
+ throw;
+ }
// Import the .js file where most of the code is.
this.Page.ClientScript.RegisterClientScriptResource(typeof(OpenIdSelector), EmbeddedScriptResourceName);
@@ -288,6 +349,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
/// </summary>
/// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter"/> object that receives the server control content.</param>
protected override void Render(HtmlTextWriter writer) {
+ Contract.Assume(writer != null, "Missing contract");
writer.AddAttribute(HtmlTextWriterAttribute.Class, "OpenIdProviders");
writer.RenderBeginTag(HtmlTextWriterTag.Ul);