summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--samples/OpenIdProviderWebForms/Code/URLRewriter.cs63
-rw-r--r--samples/OpenIdProviderWebForms/Code/Util.cs9
-rw-r--r--samples/OpenIdProviderWebForms/Global.asax.cs9
-rw-r--r--samples/OpenIdProviderWebForms/OpenIdProviderWebForms.csproj1
-rw-r--r--samples/OpenIdProviderWebForms/Web.config15
-rw-r--r--samples/OpenIdProviderWebForms/user.aspx.cs18
6 files changed, 10 insertions, 105 deletions
diff --git a/samples/OpenIdProviderWebForms/Code/URLRewriter.cs b/samples/OpenIdProviderWebForms/Code/URLRewriter.cs
deleted file mode 100644
index be65e0a..0000000
--- a/samples/OpenIdProviderWebForms/Code/URLRewriter.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-namespace OpenIdProviderWebForms.Code {
- using System.Configuration;
- using System.Diagnostics;
- using System.Text.RegularExpressions;
- using System.Web;
- using System.Xml;
-
- // nicked from http://www.codeproject.com/aspnet/URLRewriter.asp
- public class URLRewriter : IConfigurationSectionHandler {
- public static log4net.ILog Logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
-
- protected XmlNode rules = null;
-
- protected URLRewriter() {
- }
-
- public static void Process() {
- URLRewriter rewriter = (URLRewriter)ConfigurationManager.GetSection("urlrewrites");
-
- string subst = rewriter.GetSubstitution(HttpContext.Current.Request.Path);
-
- if (!string.IsNullOrEmpty(subst)) {
- Logger.InfoFormat("Rewriting url '{0}' to '{1}' ", HttpContext.Current.Request.Path, subst);
- HttpContext.Current.RewritePath(subst);
- }
- }
-
- public string GetSubstitution(string path) {
- foreach (XmlNode node in this.rules.SelectNodes("rule")) {
- // get the url and rewrite nodes
- XmlNode urlNode = node.SelectSingleNode("url");
- XmlNode rewriteNode = node.SelectSingleNode("rewrite");
-
- // check validity of the values
- if (urlNode == null || string.IsNullOrEmpty(urlNode.InnerText)
- || rewriteNode == null || string.IsNullOrEmpty(rewriteNode.InnerText)) {
- Logger.Warn("Invalid urlrewrites rule discovered in web.config file.");
- continue;
- }
-
- string oldValue = HttpContext.Current.Response.ApplyAppPathModifier(urlNode.InnerText);
-
- Regex reg = new Regex(oldValue, RegexOptions.IgnoreCase);
-
- // if match, return the substitution
- Match match = reg.Match(path);
- if (match.Success) {
- return reg.Replace(path, HttpContext.Current.Response.ApplyAppPathModifier(rewriteNode.InnerText));
- }
- }
-
- return null; // no rewrite
- }
-
- #region Implementation of IConfigurationSectionHandler
- public object Create(object parent, object configContext, XmlNode section) {
- this.rules = section;
-
- return this;
- }
- #endregion
- }
-} \ No newline at end of file
diff --git a/samples/OpenIdProviderWebForms/Code/Util.cs b/samples/OpenIdProviderWebForms/Code/Util.cs
index 6493e67..84d3c63 100644
--- a/samples/OpenIdProviderWebForms/Code/Util.cs
+++ b/samples/OpenIdProviderWebForms/Code/Util.cs
@@ -24,11 +24,14 @@ namespace OpenIdProviderWebForms.Code {
}
public static Identifier BuildIdentityUrl() {
- string username = HttpContext.Current.User.Identity.Name;
+ return BuildIdentityUrl(HttpContext.Current.User.Identity.Name);
+ }
- // be sure to normalize case the way the user's identity page does.
+ public static Identifier BuildIdentityUrl(string username) {
+ // This sample Provider has a custom policy for normalizing URIs, which is that the whole
+ // path of the URI be lowercase except for the first letter of the username.
username = username.Substring(0, 1).ToUpperInvariant() + username.Substring(1).ToLowerInvariant();
- return new Uri(HttpContext.Current.Request.Url, HttpContext.Current.Response.ApplyAppPathModifier("~/user/" + username));
+ return new Uri(HttpContext.Current.Request.Url, HttpContext.Current.Response.ApplyAppPathModifier("~/user.aspx/" + username));
}
internal static void ProcessAuthenticationChallenge(IAuthenticationRequest idrequest) {
diff --git a/samples/OpenIdProviderWebForms/Global.asax.cs b/samples/OpenIdProviderWebForms/Global.asax.cs
index 79aca23..3048b17 100644
--- a/samples/OpenIdProviderWebForms/Global.asax.cs
+++ b/samples/OpenIdProviderWebForms/Global.asax.cs
@@ -39,13 +39,6 @@ namespace OpenIdProviderWebForms {
}
protected void Application_BeginRequest(object sender, EventArgs e) {
- /*
- * The URLRewriter was taken from http://www.codeproject.com/aspnet/URLRewriter.asp and modified slightly.
- * It will read the config section called 'urlrewrites' from web.config and process each rule
- * The rules are set of url transformations defined using regular expressions with support for substitutions (the ability to extract regex-matched portions of a string).
- * There is only one rule currenty defined. It rewrites urls like: user/john ->user.aspx?username=john
- */
- //// System.Diagnostics.Debugger.Launch();
Logger.DebugFormat("Processing {0} on {1} ", this.Request.HttpMethod, this.stripQueryString(this.Request.Url));
if (Request.QueryString.Count > 0) {
Logger.DebugFormat("Querystring follows: \n{0}", ToString(Request.QueryString));
@@ -53,8 +46,6 @@ namespace OpenIdProviderWebForms {
if (Request.Form.Count > 0) {
Logger.DebugFormat("Posted form follows: \n{0}", ToString(Request.Form));
}
-
- URLRewriter.Process();
}
protected void Application_AuthenticateRequest(object sender, EventArgs e) {
diff --git a/samples/OpenIdProviderWebForms/OpenIdProviderWebForms.csproj b/samples/OpenIdProviderWebForms/OpenIdProviderWebForms.csproj
index 5203150..c45b0f5 100644
--- a/samples/OpenIdProviderWebForms/OpenIdProviderWebForms.csproj
+++ b/samples/OpenIdProviderWebForms/OpenIdProviderWebForms.csproj
@@ -91,7 +91,6 @@
</Compile>
<Compile Include="Code\ReadOnlyXmlMembershipProvider.cs" />
<Compile Include="Code\TracePageAppender.cs" />
- <Compile Include="Code\URLRewriter.cs" />
<Compile Include="Code\Util.cs" />
<Compile Include="decide.aspx.cs">
<DependentUpon>decide.aspx</DependentUpon>
diff --git a/samples/OpenIdProviderWebForms/Web.config b/samples/OpenIdProviderWebForms/Web.config
index 6fdbb3c..85b3c30 100644
--- a/samples/OpenIdProviderWebForms/Web.config
+++ b/samples/OpenIdProviderWebForms/Web.config
@@ -10,7 +10,6 @@
<configuration>
<configSections>
<section name="uri" type="System.Configuration.UriSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
- <section name="urlrewrites" type="OpenIdProviderWebForms.Code.URLRewriter" requirePermission="false"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler" requirePermission="false"/>
<section name="dotNetOpenAuth" type="DotNetOpenAuth.Configuration.DotNetOpenAuthSection" requirePermission="false" allowLocation="true"/>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
@@ -58,20 +57,6 @@
</settings>
</system.net>
- <!--
- Original version created by Richard Birkby (2002-02-22, http://www.codeproject.com/aspnet/URLRewriter.asp)
- Maps from old website to new website using Regular Expressions
- rule/url - old website url (Regular Expression)
- rule/rewrite - new website replacement expression
- Of two or more rules which match a given request, the first will always take precedance.
- -->
- <urlrewrites>
- <rule>
- <!-- This rewrites urls like: user/john ->user.aspx?username=john-->
- <url>~/user/(.*)</url>
- <rewrite>~/user.aspx?username=$1</rewrite>
- </rule>
- </urlrewrites>
<system.web>
<!--
Set compilation debug="true" to insert debugging
diff --git a/samples/OpenIdProviderWebForms/user.aspx.cs b/samples/OpenIdProviderWebForms/user.aspx.cs
index 63eb1d6..5cd84c9 100644
--- a/samples/OpenIdProviderWebForms/user.aspx.cs
+++ b/samples/OpenIdProviderWebForms/user.aspx.cs
@@ -1,33 +1,23 @@
namespace OpenIdProviderWebForms {
using System;
using DotNetOpenAuth.OpenId.Provider;
+ using OpenIdProviderWebForms.Code;
/// <summary>
/// This page is a required as part of the service discovery phase of the openid protocol (step 1).
/// </summary>
/// <remarks>
- /// <para>How does a url like http://www.myserver.com/user/bob map to http://www.myserver.com/user.aspx?username=bob ?
- /// Check out gobal.asax and the URLRewriter class. Essentially there's a little framework that allows for URLRewrting using the HttpContext.Current.RewritePath method.</para>
- /// <para>A url such as http://www.myserver.com/user/bob which is entered on the consumer side will cause this page to be invoked.
- /// This page must be parsed by the openid compatible consumer and the url of the openid server is extracted from href in: rel="openid.server" href="?".
- /// It is the responsibility of the consumer to redirect the user to this url.</para>
/// <para>The XRDS (or Yadis) content is also rendered to provide the consumer with an alternative discovery mechanism. The Yadis protocol allows the consumer
/// to provide the user with a more flexible range of authentication mechanisms (which ever has been defined in xrds.aspx). See http://en.wikipedia.org/wiki/Yadis.</para>
/// </remarks>
public partial class user : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
- this.usernameLabel.Text = Request.QueryString["username"];
+ this.usernameLabel.Text = Util.ExtractUserName(Page.Request.Url);
}
protected void IdentityEndpoint20_NormalizeUri(object sender, IdentityEndpointNormalizationEventArgs e) {
- // This sample Provider has a custom policy for normalizing URIs, which is that the whole
- // path of the URI be lowercase except for the first letter of the username.
- UriBuilder normalized = new UriBuilder(e.UserSuppliedIdentifier);
- string username = Request.QueryString["username"].TrimEnd('/').ToLowerInvariant();
- username = username.Substring(0, 1).ToUpperInvariant() + username.Substring(1);
- normalized.Path = Response.ApplyAppPathModifier("~/user/" + username);
- normalized.Scheme = "http"; // for a real Provider, this should be HTTPS if supported.
- e.NormalizedIdentifier = normalized.Uri;
+ string username = Util.ExtractUserName(Page.Request.Url);
+ e.NormalizedIdentifier = new Uri(Util.BuildIdentityUrl(username));
}
}
} \ No newline at end of file