summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-05-15 09:23:19 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-05-15 09:23:19 -0700
commitea7c6614674354d0c1cd393cd86d48eb4e8831ef (patch)
tree6458fc25a87b6eda7ac73d3516c4684dc71d5132 /src
parente86b9beaf7164d0e86b42ec2e8d161f06ce0fdf0 (diff)
downloadDotNetOpenAuth-ea7c6614674354d0c1cd393cd86d48eb4e8831ef.zip
DotNetOpenAuth-ea7c6614674354d0c1cd393cd86d48eb4e8831ef.tar.gz
DotNetOpenAuth-ea7c6614674354d0c1cd393cd86d48eb4e8831ef.tar.bz2
Added support for the OpenID User Interface extension.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth/DotNetOpenAuth.csproj2
-rw-r--r--src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs1
-rw-r--r--src/DotNetOpenAuth/OpenId/Extensions/UI/UIModes.cs25
-rw-r--r--src/DotNetOpenAuth/OpenId/Extensions/UI/UIRequest.cs156
4 files changed, 184 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
index 3329367..776792b 100644
--- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj
+++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
@@ -351,6 +351,8 @@
<Compile Include="OpenId\Extensions\SimpleRegistration\Constants.cs" />
<Compile Include="OpenId\Extensions\SimpleRegistration\DemandLevel.cs" />
<Compile Include="OpenId\Extensions\SimpleRegistration\Gender.cs" />
+ <Compile Include="OpenId\Extensions\UI\UIModes.cs" />
+ <Compile Include="OpenId\Extensions\UI\UIRequest.cs" />
<Compile Include="OpenId\Identifier.cs" />
<Compile Include="OpenId\IdentifierContract.cs" />
<Compile Include="OpenId\Interop\AuthenticationResponseShim.cs" />
diff --git a/src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs b/src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs
index 0e26860..2f11853 100644
--- a/src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs
+++ b/src/DotNetOpenAuth/Messaging/Reflection/MessagePart.cs
@@ -65,6 +65,7 @@ namespace DotNetOpenAuth.Messaging.Reflection {
Map<Realm>(realm => realm.ToString(), str => new Realm(str));
Map<Identifier>(id => id.ToString(), str => Identifier.Parse(str));
Map<bool>(value => value.ToString().ToLowerInvariant(), str => bool.Parse(str));
+ Map<CultureInfo>(c => c.Name, str => new CultureInfo(str));
}
/// <summary>
diff --git a/src/DotNetOpenAuth/OpenId/Extensions/UI/UIModes.cs b/src/DotNetOpenAuth/OpenId/Extensions/UI/UIModes.cs
new file mode 100644
index 0000000..8e3e20f
--- /dev/null
+++ b/src/DotNetOpenAuth/OpenId/Extensions/UI/UIModes.cs
@@ -0,0 +1,25 @@
+//-----------------------------------------------------------------------
+// <copyright file="UIModes.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenId.Extensions.UI {
+ /// <summary>
+ /// Valid values for the <c>mode</c> parameter of the OpenID User Interface extension.
+ /// </summary>
+ public static class UIModes {
+ /// <summary>
+ /// Indicates that the Provider's authentication page appears in a popup window.
+ /// </summary>
+ /// <value>The constant <c>"popup"</c>.</value>
+ /// <remarks>
+ /// <para>The RP SHOULD create the popup to be 450 pixels wide and 500 pixels tall. The popup MUST have the address bar displayed, and MUST be in a standalone browser window. The contents of the popup MUST NOT be framed by the RP. </para>
+ /// <para>The RP SHOULD open the popup centered above the main browser window, and SHOULD dim the contents of the parent window while the popup is active. The RP SHOULD ensure that the user is not surprised by the appearance of the popup, and understands how to interact with it. </para>
+ /// <para>To keep the user popup user experience consistent, it is RECOMMENDED that the OP does not resize the popup window unless the OP requires additional space to show special features that are not usually displayed as part of the default popup user experience. </para>
+ /// <para>The OP MAY close the popup without returning a response to the RP. Closing the popup without sending a response should be interpreted as a negative assertion. </para>
+ /// <para>The response to an authentication request in a popup is unchanged from [OpenID 2.0] (OpenID 2.0 Workgroup, “OpenID 2.0,” .). Relying Parties detecting that the popup was closed without receiving an authentication response SHOULD interpret the close event to be a negative assertion. </para>
+ /// </remarks>
+ public const string Popup = "popup";
+ }
+}
diff --git a/src/DotNetOpenAuth/OpenId/Extensions/UI/UIRequest.cs b/src/DotNetOpenAuth/OpenId/Extensions/UI/UIRequest.cs
new file mode 100644
index 0000000..d03fcaa
--- /dev/null
+++ b/src/DotNetOpenAuth/OpenId/Extensions/UI/UIRequest.cs
@@ -0,0 +1,156 @@
+//-----------------------------------------------------------------------
+// <copyright file="UIRequest.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OpenId.Extensions.UI {
+ using System;
+ using System.Collections.Generic;
+ using System.Globalization;
+ using System.Linq;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OpenId.Messages;
+
+ /// <summary>
+ /// OpenID User Interface extension 1.0 request message.
+ /// </summary>
+ /// <remarks>
+ /// <para>Implements the extension described by: http://wiki.openid.net/f/openid_ui_extension_draft01.html </para>
+ /// <para>This extension only applies to checkid_setup requests, since checkid_immediate requests display
+ /// no UI to the user. </para>
+ /// <para>For rules about how the popup window should be displayed, please see the documentation of
+ /// <see cref="UIModes.Popup"/>. </para>
+ /// <para>An RP may determine whether an arbitrary OP supports this extension (and thereby determine
+ /// whether to use a standard full window redirect or a popup) via the
+ /// <see cref="IProviderEndpoint.IsExtensionSupported"/> method on the <see cref="IAuthenticationRequest.Provider"/>
+ /// object.</para>
+ /// </remarks>
+ public class UIRequest : IOpenIdMessageExtension, IMessageWithEvents {
+ /// <summary>
+ /// Backing store for <see cref="ExtraData"/>.
+ /// </summary>
+ private Dictionary<string, string> extraData = new Dictionary<string, string>();
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="UIRequest"/> class.
+ /// </summary>
+ public UIRequest() {
+ this.PreferredLanguage = CultureInfo.CurrentUICulture;
+ }
+
+ /// <summary>
+ /// Gets or sets the user's preferred language.
+ /// </summary>
+ /// <value>The default is the <see cref="CultureInfo.CurrentUICulture"/> of the thread that created this instance.</value>
+ /// <remarks>
+ /// The user's preferred language, reusing the Language Tag format used by the [Language Preference Attribute] (axschema.org, “Language Preference Attribute,” .) for [OpenID Attribute Exchange] (Hardt, D., Bufu, J., and J. Hoyt, “OpenID Attribute Exchange 1.0,” .) and defined in [RFC4646] (Phillips, A. and M. Davis, “Tags for Identifying Languages,” .). For example "en-US" represents the English language as spoken in the United States, and "fr-CA" represents the French language spoken in Canada.
+ /// </remarks>
+ [MessagePart("lang", AllowEmpty = false)]
+ public CultureInfo PreferredLanguage { get; set; }
+
+ /// <summary>
+ /// Gets the style of UI that the RP is hosting the OP's authentication page in.
+ /// </summary>
+ /// <value>Some value from the <see cref="UIModes"/> class. Defaults to <see cref="UIModes.Popup"/>.</value>
+ [MessagePart("mode", AllowEmpty = false, IsRequired = true)]
+ public string Mode { get { return UIModes.Popup; } }
+
+ #region IOpenIdMessageExtension Members
+
+ /// <summary>
+ /// Gets the TypeURI the extension uses in the OpenID protocol and in XRDS advertisements.
+ /// </summary>
+ /// <value></value>
+ public string TypeUri { get { return "http://specs.openid.net/extensions/ui/1.0"; } }
+
+ /// <summary>
+ /// Gets the additional TypeURIs that are supported by this extension, in preferred order.
+ /// May be empty if none other than <see cref="TypeUri"/> is supported, but
+ /// should not be null.
+ /// </summary>
+ /// <remarks>
+ /// Useful for reading in messages with an older version of an extension.
+ /// The value in the <see cref="TypeUri"/> property is always checked before
+ /// trying this list.
+ /// If you do support multiple versions of an extension using this method,
+ /// consider adding a CreateResponse method to your request extension class
+ /// so that the response can have the context it needs to remain compatible
+ /// given the version of the extension in the request message.
+ /// The <see cref="Extensions.SimpleRegistration.ClaimsRequest.CreateResponse"/> for an example.
+ /// </remarks>
+ public IEnumerable<string> AdditionalSupportedTypeUris { get { return Enumerable.Empty<string>(); } }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether this extension was
+ /// signed by the sender.
+ /// </summary>
+ /// <value>
+ /// <c>true</c> if this instance is signed by the sender; otherwise, <c>false</c>.
+ /// </value>
+ public bool IsSignedByRemoteParty { get; set; }
+
+ #endregion
+
+ #region IMessage Members
+
+ /// <summary>
+ /// Gets the version of the protocol or extension this message is prepared to implement.
+ /// </summary>
+ /// <value>The value 1.0.</value>
+ /// <remarks>
+ /// Implementations of this interface should ensure that this property never returns null.
+ /// </remarks>
+ public Version Version {
+ get { return new Version(1, 0); }
+ }
+
+ /// <summary>
+ /// Gets the extra, non-standard Protocol parameters included in the message.
+ /// </summary>
+ /// <remarks>
+ /// Implementations of this interface should ensure that this property never returns null.
+ /// </remarks>
+ public IDictionary<string, string> ExtraData {
+ get { return this.extraData; }
+ }
+
+ /// <summary>
+ /// Checks the message state for conformity to the protocol specification
+ /// and throws an exception if the message is invalid.
+ /// </summary>
+ /// <remarks>
+ /// <para>Some messages have required fields, or combinations of fields that must relate to each other
+ /// in specialized ways. After deserializing a message, this method checks the state of the
+ /// message to see if it conforms to the protocol.</para>
+ /// <para>Note that this property should <i>not</i> check signatures or perform any state checks
+ /// outside this scope of this particular message.</para>
+ /// </remarks>
+ /// <exception cref="ProtocolException">Thrown if the message is invalid.</exception>
+ public void EnsureValidMessage() {
+ }
+
+ #endregion
+
+ #region IMessageWithEvents Members
+
+ /// <summary>
+ /// Called when the message is about to be transmitted,
+ /// before it passes through the channel binding elements.
+ /// </summary>
+ public void OnSending() {
+ }
+
+ /// <summary>
+ /// Called when the message has been received,
+ /// after it passes through the channel binding elements.
+ /// </summary>
+ public void OnReceiving() {
+ if (this.PreferredLanguage != null) {
+ // TODO: see if we can change the CultureInfo.CurrentUICulture somehow
+ }
+ }
+
+ #endregion
+ }
+}