summaryrefslogtreecommitdiffstats
path: root/samples/OpenIdProviderWebForms/Code/Util.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-02-01 13:18:33 -0800
committerAndrew <andrewarnott@gmail.com>2009-02-01 13:18:33 -0800
commite6512c223cb078b5f2fd4ea4abb28810ecca8c47 (patch)
treebb9dbea5e485a9a2c6aca44308659577333fba26 /samples/OpenIdProviderWebForms/Code/Util.cs
parente865ec7da293496d6c2e67039b86c4ef9ded5a6c (diff)
downloadDotNetOpenAuth-e6512c223cb078b5f2fd4ea4abb28810ecca8c47.zip
DotNetOpenAuth-e6512c223cb078b5f2fd4ea4abb28810ecca8c47.tar.gz
DotNetOpenAuth-e6512c223cb078b5f2fd4ea4abb28810ecca8c47.tar.bz2
Renamed OpenID Provider sample directory to match project name.
Diffstat (limited to 'samples/OpenIdProviderWebForms/Code/Util.cs')
-rw-r--r--samples/OpenIdProviderWebForms/Code/Util.cs56
1 files changed, 56 insertions, 0 deletions
diff --git a/samples/OpenIdProviderWebForms/Code/Util.cs b/samples/OpenIdProviderWebForms/Code/Util.cs
new file mode 100644
index 0000000..5cec951
--- /dev/null
+++ b/samples/OpenIdProviderWebForms/Code/Util.cs
@@ -0,0 +1,56 @@
+//-----------------------------------------------------------------------
+// <copyright file="Util.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace OpenIdProviderWebForms.Code {
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics;
+ using System.Net;
+ using System.Text;
+ using System.Web;
+ using DotNetOpenAuth.OpenId;
+ using DotNetOpenAuth.OpenId.Provider;
+
+ public class Util {
+ public static string ExtractUserName(Uri url) {
+ return url.Segments[url.Segments.Length - 1];
+ }
+
+ public static string ExtractUserName(Identifier identifier) {
+ return ExtractUserName(new Uri(identifier.ToString()));
+ }
+
+ public static Identifier BuildIdentityUrl() {
+ string username = HttpContext.Current.User.Identity.Name;
+
+ // be sure to normalize case the way the user's identity page does.
+ username = username.Substring(0, 1).ToUpperInvariant() + username.Substring(1).ToLowerInvariant();
+ return new Uri(HttpContext.Current.Request.Url, "/user/" + username);
+ }
+
+ internal static void ProcessAuthenticationChallenge(IAuthenticationRequest idrequest) {
+ if (idrequest.Immediate) {
+ if (idrequest.IsDirectedIdentity) {
+ if (HttpContext.Current.User.Identity.IsAuthenticated) {
+ idrequest.LocalIdentifier = Util.BuildIdentityUrl();
+ idrequest.IsAuthenticated = true;
+ } else {
+ idrequest.IsAuthenticated = false;
+ }
+ } else {
+ string userOwningOpenIdUrl = Util.ExtractUserName(idrequest.LocalIdentifier);
+
+ // NOTE: in a production provider site, you may want to only
+ // respond affirmatively if the user has already authorized this consumer
+ // to know the answer.
+ idrequest.IsAuthenticated = userOwningOpenIdUrl == HttpContext.Current.User.Identity.Name;
+ }
+ } else {
+ HttpContext.Current.Response.Redirect("~/decide.aspx", true);
+ }
+ }
+ }
+} \ No newline at end of file