summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OpenId.UI
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2011-07-27 06:12:47 -0600
committerAndrew Arnott <andrewarnott@gmail.com>2011-07-27 06:12:47 -0600
commit69984da752a43a255fde26dedde7dff9ec6ebfea (patch)
treedd65b9c1350396489181570f6c433e553bcb2877 /src/DotNetOpenAuth.OpenId.UI
parentd3b9f41d7b4171dada6d4ba42652cfcb60172bae (diff)
downloadDotNetOpenAuth-69984da752a43a255fde26dedde7dff9ec6ebfea.zip
DotNetOpenAuth-69984da752a43a255fde26dedde7dff9ec6ebfea.tar.gz
DotNetOpenAuth-69984da752a43a255fde26dedde7dff9ec6ebfea.tar.bz2
Extracted OpenID UI project.
Diffstat (limited to 'src/DotNetOpenAuth.OpenId.UI')
-rw-r--r--src/DotNetOpenAuth.OpenId.UI/DotNetOpenAuth.OpenId.UI.csproj43
-rw-r--r--src/DotNetOpenAuth.OpenId.UI/Properties/AssemblyInfo.cs64
-rw-r--r--src/DotNetOpenAuth.OpenId.UI/XrdsPublisher.cs229
3 files changed, 336 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.OpenId.UI/DotNetOpenAuth.OpenId.UI.csproj b/src/DotNetOpenAuth.OpenId.UI/DotNetOpenAuth.OpenId.UI.csproj
new file mode 100644
index 0000000..5043536
--- /dev/null
+++ b/src/DotNetOpenAuth.OpenId.UI/DotNetOpenAuth.OpenId.UI.csproj
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.props))\EnlistmentInfo.props" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.props))' != '' " />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ </PropertyGroup>
+ <Import Project="$(ProjectRoot)tools\DotNetOpenAuth.props" />
+ <PropertyGroup>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{75E13AAE-7D51-4421-ABFD-3F3DC91F576E}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>DotNetOpenAuth</RootNamespace>
+ <AssemblyName>DotNetOpenAuth.OpenId.UI</AssemblyName>
+ </PropertyGroup>
+ <Import Project="$(ProjectRoot)tools\DotNetOpenAuth.Product.props" />
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="XrdsPublisher.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\DotNetOpenAuth.Messaging\DotNetOpenAuth.Messaging.csproj">
+ <Project>{60426312-6AE5-4835-8667-37EDEA670222}</Project>
+ <Name>DotNetOpenAuth.Messaging</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\DotNetOpenAuth.OpenId\DotNetOpenAuth.OpenId.csproj">
+ <Project>{3896A32A-E876-4C23-B9B8-78E17D134CD3}</Project>
+ <Name>DotNetOpenAuth.OpenId</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\Org.Mentalis.Security.Cryptography\Org.Mentalis.Security.Cryptography.csproj">
+ <Project>{26DC877F-5987-48DD-9DDB-E62F2DE0E150}</Project>
+ <Name>Org.Mentalis.Security.Cryptography</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <Import Project="$(ProjectRoot)tools\DotNetOpenAuth.targets" />
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))\EnlistmentInfo.targets" Condition=" '$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), EnlistmentInfo.targets))' != '' " />
+</Project> \ No newline at end of file
diff --git a/src/DotNetOpenAuth.OpenId.UI/Properties/AssemblyInfo.cs b/src/DotNetOpenAuth.OpenId.UI/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..e4d1746
--- /dev/null
+++ b/src/DotNetOpenAuth.OpenId.UI/Properties/AssemblyInfo.cs
@@ -0,0 +1,64 @@
+//-----------------------------------------------------------------------
+// <copyright file="AssemblyInfo.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+// We DON'T put an AssemblyVersionAttribute in here because it is generated in the build.
+
+using System;
+using System.Diagnostics.Contracts;
+using System.Net;
+using System.Reflection;
+using System.Resources;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Security.Permissions;
+using System.Web.UI;
+
+[assembly: TagPrefix("DotNetOpenAuth.OpenId", "openid")]
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("DotNetOpenAuth OpenID")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("DotNetOpenAuth")]
+[assembly: AssemblyCopyright("Copyright © 2008")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+[assembly: NeutralResourcesLanguage("en-US")]
+[assembly: CLSCompliant(true)]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("7d73990c-47c0-4256-9f20-a893add9e289")]
+
+[assembly: ContractVerification(true)]
+
+#if StrongNameSigned
+// See comment at top of this file. We need this so that strong-naming doesn't
+// keep this assembly from being useful to shared host (medium trust) web sites.
+[assembly: AllowPartiallyTrustedCallers]
+
+[assembly: InternalsVisibleTo("DotNetOpenAuth.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100AD093C3765257C89A7010E853F2C7C741FF92FA8ACE06D7B8254702CAD5CF99104447F63AB05F8BB6F51CE0D81C8C93D2FCE8C20AAFF7042E721CBA16EAAE98778611DED11C0ABC8900DC5667F99B50A9DADEC24DBD8F2C91E3E8AD300EF64F1B4B9536CEB16FB440AF939F57624A9B486F867807C649AE4830EAB88C6C03998")]
+[assembly: InternalsVisibleTo("DotNetOpenAuth.OAuth, PublicKey=0024000004800000940000000602000000240000525341310004000001000100AD093C3765257C89A7010E853F2C7C741FF92FA8ACE06D7B8254702CAD5CF99104447F63AB05F8BB6F51CE0D81C8C93D2FCE8C20AAFF7042E721CBA16EAAE98778611DED11C0ABC8900DC5667F99B50A9DADEC24DBD8F2C91E3E8AD300EF64F1B4B9536CEB16FB440AF939F57624A9B486F867807C649AE4830EAB88C6C03998")]
+[assembly: InternalsVisibleTo("DotNetOpenAuth.OpenId.RelyingParty, PublicKey=0024000004800000940000000602000000240000525341310004000001000100AD093C3765257C89A7010E853F2C7C741FF92FA8ACE06D7B8254702CAD5CF99104447F63AB05F8BB6F51CE0D81C8C93D2FCE8C20AAFF7042E721CBA16EAAE98778611DED11C0ABC8900DC5667F99B50A9DADEC24DBD8F2C91E3E8AD300EF64F1B4B9536CEB16FB440AF939F57624A9B486F867807C649AE4830EAB88C6C03998")]
+[assembly: InternalsVisibleTo("DotNetOpenAuth.OpenId.RelyingParty.UI, PublicKey=0024000004800000940000000602000000240000525341310004000001000100AD093C3765257C89A7010E853F2C7C741FF92FA8ACE06D7B8254702CAD5CF99104447F63AB05F8BB6F51CE0D81C8C93D2FCE8C20AAFF7042E721CBA16EAAE98778611DED11C0ABC8900DC5667F99B50A9DADEC24DBD8F2C91E3E8AD300EF64F1B4B9536CEB16FB440AF939F57624A9B486F867807C649AE4830EAB88C6C03998")]
+[assembly: InternalsVisibleTo("DotNetOpenAuth.OpenId.Provider, PublicKey=0024000004800000940000000602000000240000525341310004000001000100AD093C3765257C89A7010E853F2C7C741FF92FA8ACE06D7B8254702CAD5CF99104447F63AB05F8BB6F51CE0D81C8C93D2FCE8C20AAFF7042E721CBA16EAAE98778611DED11C0ABC8900DC5667F99B50A9DADEC24DBD8F2C91E3E8AD300EF64F1B4B9536CEB16FB440AF939F57624A9B486F867807C649AE4830EAB88C6C03998")]
+[assembly: InternalsVisibleTo("DotNetOpenAuth.OpenId.Provider.UI, PublicKey=0024000004800000940000000602000000240000525341310004000001000100AD093C3765257C89A7010E853F2C7C741FF92FA8ACE06D7B8254702CAD5CF99104447F63AB05F8BB6F51CE0D81C8C93D2FCE8C20AAFF7042E721CBA16EAAE98778611DED11C0ABC8900DC5667F99B50A9DADEC24DBD8F2C91E3E8AD300EF64F1B4B9536CEB16FB440AF939F57624A9B486F867807C649AE4830EAB88C6C03998")]
+#else
+[assembly: InternalsVisibleTo("DotNetOpenAuth.Test")]
+[assembly: InternalsVisibleTo("DotNetOpenAuth.OAuth")]
+[assembly: InternalsVisibleTo("DotNetOpenAuth.OpenId.RelyingParty")]
+[assembly: InternalsVisibleTo("DotNetOpenAuth.OpenId.RelyingParty.UI")]
+[assembly: InternalsVisibleTo("DotNetOpenAuth.OpenId.Provider")]
+[assembly: InternalsVisibleTo("DotNetOpenAuth.OpenId.Provider.UI")]
+#endif
diff --git a/src/DotNetOpenAuth.OpenId.UI/XrdsPublisher.cs b/src/DotNetOpenAuth.OpenId.UI/XrdsPublisher.cs
new file mode 100644
index 0000000..03c32c1
--- /dev/null
+++ b/src/DotNetOpenAuth.OpenId.UI/XrdsPublisher.cs
@@ -0,0 +1,229 @@
+//-----------------------------------------------------------------------
+// <copyright file="XrdsPublisher.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth {
+ using System;
+ using System.Collections.Generic;
+ using System.ComponentModel;
+ using System.Diagnostics.CodeAnalysis;
+ using System.Diagnostics.Contracts;
+ using System.Drawing.Design;
+ using System.Text;
+ using System.Web;
+ using System.Web.UI;
+ using System.Web.UI.WebControls;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.Yadis;
+
+ /// <summary>
+ /// The locations the YADIS protocol describes can contain a reference
+ /// to an XRDS document.
+ /// </summary>
+ [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xrds", Justification = "Correct spelling")]
+ [Flags]
+ public enum XrdsUrlLocations {
+ /// <summary>
+ /// The XRDS document should not be advertised anywhere.
+ /// </summary>
+ /// <remarks>
+ /// When the XRDS document is not referenced from anywhere,
+ /// the XRDS content is only available when
+ /// <see cref="XrdsPublisher.XrdsAutoAnswer"/> is <c>true</c>
+ /// and the discovering client includes an
+ /// "Accept: application/xrds+xml" HTTP header.
+ /// </remarks>
+ None = 0x0,
+
+ /// <summary>
+ /// Indicates XRDS document referencing from an HTTP protocol header (outside the HTML).
+ /// </summary>
+ HttpHeader = 0x1,
+
+ /// <summary>
+ /// Indicates XRDS document referencing from within an HTML page's &lt;HEAD&gt; tag.
+ /// </summary>
+ HtmlMeta = 0x2,
+
+ /// <summary>
+ /// Indicates XRDS document referencing in both HTTP headers and HTML HEAD tags.
+ /// </summary>
+ Both = 0x3,
+ }
+
+ /// <summary>
+ /// An ASP.NET control that advertises an XRDS document and even responds to specially
+ /// crafted requests to retrieve it.
+ /// </summary>
+ [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xrds", Justification = "Correct spelling")]
+ [DefaultProperty("XrdsLocation")]
+ [ToolboxData("<{0}:XrdsPublisher runat=server></{0}:XrdsPublisher>")]
+ public class XrdsPublisher : Control {
+ /// <summary>
+ /// The view state key to ues for storing the value of the <see cref="XrdsUrl"/> property.
+ /// </summary>
+ private const string XrdsUrlViewStateKey = "XrdsUrl";
+
+ /// <summary>
+ /// The default value for the <see cref="XrdsAdvertisement"/> property.
+ /// </summary>
+ private const XrdsUrlLocations XrdsAdvertisementDefault = XrdsUrlLocations.HttpHeader;
+
+ /// <summary>
+ /// The view state key to ues for storing the value of the <see cref="XrdsAdvertisement"/> property.
+ /// </summary>
+ private const string XrdsAdvertisementViewStateKey = "XrdsAdvertisement";
+
+ /// <summary>
+ /// The default value for the <see cref="XrdsAutoAnswer"/> property.
+ /// </summary>
+ private const bool XrdsAutoAnswerDefault = true;
+
+ /// <summary>
+ /// The view state key to ues for storing the value of the <see cref="XrdsAutoAnswer"/> property.
+ /// </summary>
+ private const string XrdsAutoAnswerViewStateKey = "XrdsAutoAnswer";
+
+ /// <summary>
+ /// The default value for the <see cref="Enabled"/> property.
+ /// </summary>
+ private const bool EnabledDefault = true;
+
+ /// <summary>
+ /// The view state key to ues for storing the value of the <see cref="Enabled"/> property.
+ /// </summary>
+ private const string EnabledViewStateKey = "Enabled";
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="XrdsPublisher"/> class.
+ /// </summary>
+ public XrdsPublisher() {
+ Reporting.RecordFeatureUse(this);
+ }
+
+ #region Properties
+
+ /// <summary>
+ /// Gets or sets the location of the XRDS document.
+ /// </summary>
+ [SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings", Justification = "Property grid")]
+ [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xrds", Justification = "Correct spelling")]
+ [Category("Behavior"), Bindable(true)]
+ [UrlProperty, Editor("System.Web.UI.Design.UrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
+ public string XrdsUrl {
+ get {
+ return (string)ViewState[XrdsUrlViewStateKey];
+ }
+
+ set {
+ UriUtil.ValidateResolvableUrl(Page, DesignMode, value);
+ ViewState[XrdsUrlViewStateKey] = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets where the XRDS document URL is advertised in the web response.
+ /// </summary>
+ [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xrds", Justification = "Correct spelling")]
+ [Category("Behavior"), DefaultValue(XrdsAdvertisementDefault), Bindable(true)]
+ [Description("Where the XRDS document URL is advertised in the web response.")]
+ public XrdsUrlLocations XrdsAdvertisement {
+ get {
+ return ViewState[XrdsAdvertisementViewStateKey] == null ?
+ XrdsAdvertisementDefault : (XrdsUrlLocations)ViewState[XrdsAdvertisementViewStateKey];
+ }
+
+ set {
+ ViewState[XrdsAdvertisementViewStateKey] = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether a specially crafted YADIS
+ /// search for an XRDS document is immediately answered by this control.
+ /// </summary>
+ [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Xrds", Justification = "Correct spelling")]
+ [Category("Behavior"), DefaultValue(XrdsAutoAnswerDefault), Bindable(true)]
+ [Description("Whether XRDS requests should be immediately answered with the XRDS document if it is served by this web application.")]
+ public bool XrdsAutoAnswer {
+ get {
+ return ViewState[XrdsAutoAnswerViewStateKey] == null ?
+ XrdsAutoAnswerDefault : (bool)ViewState[XrdsAutoAnswerViewStateKey];
+ }
+
+ set {
+ ViewState[XrdsAutoAnswerViewStateKey] = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether the XRDS document is advertised.
+ /// </summary>
+ [Category("Behavior"), DefaultValue(EnabledDefault)]
+ public bool Enabled {
+ get {
+ return ViewState[EnabledViewStateKey] == null ?
+ EnabledDefault : (bool)ViewState[EnabledViewStateKey];
+ }
+
+ set {
+ ViewState[EnabledViewStateKey] = value;
+ }
+ }
+
+ #endregion
+
+ /// <summary>
+ /// Detects YADIS requests for the XRDS document and responds immediately
+ /// if <see cref="XrdsAutoAnswer"/> is true.
+ /// </summary>
+ /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param>
+ protected override void OnLoad(EventArgs e) {
+ base.OnLoad(e);
+
+ if (!this.Enabled) {
+ return;
+ }
+
+ if (!this.Page.IsPostBack) {
+ if (this.XrdsAutoAnswer && !string.IsNullOrEmpty(this.XrdsUrl) &&
+ this.XrdsUrl.StartsWith("~/", StringComparison.Ordinal)) {
+ // Check for the presence of an accept types header that is looking
+ // for the XRDS document specifically.
+ if (this.Page.Request.AcceptTypes != null && Array.IndexOf(this.Page.Request.AcceptTypes, ContentTypes.Xrds) >= 0) {
+ // Respond to the caller immediately with an XRDS document
+ // and avoid sending the whole web page's contents to the
+ // client since it isn't interested anyway.
+ // We do NOT simply send a 301 redirect here because that would
+ // alter the Claimed Identifier.
+ this.Page.Server.Transfer(this.XrdsUrl);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Renders the HTTP Header and/or HTML HEAD tags.
+ /// </summary>
+ /// <param name="writer">The <see cref="T:System.Web.UI.HtmlTextWriter"/> object that receives the server control content.</param>
+ [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Diagnostics.Contracts.__ContractsRuntime.Assume(System.Boolean,System.String,System.String)", Justification = "Code contracts"), SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "Uri(Uri, string) accepts second arguments that Uri(Uri, new Uri(string)) does not that we must support.")]
+ protected override void Render(HtmlTextWriter writer) {
+ Contract.Assume(writer != null, "Missing contract.");
+ if (this.Enabled && this.Visible && !string.IsNullOrEmpty(this.XrdsUrl)) {
+ Uri xrdsAddress = new Uri(MessagingUtilities.GetRequestUrlFromContext(), Page.Response.ApplyAppPathModifier(this.XrdsUrl));
+ if ((this.XrdsAdvertisement & XrdsUrlLocations.HttpHeader) != 0) {
+ Page.Response.AddHeader(Yadis.Yadis.HeaderName, xrdsAddress.AbsoluteUri);
+ }
+ if ((this.XrdsAdvertisement & XrdsUrlLocations.HtmlMeta) != 0) {
+ writer.WriteBeginTag("meta");
+ writer.WriteAttribute("http-equiv", Yadis.Yadis.HeaderName);
+ writer.WriteAttribute("content", xrdsAddress.AbsoluteUri);
+ writer.Write("/>");
+ writer.WriteLine();
+ }
+ }
+ }
+ }
+}