summaryrefslogtreecommitdiffstats
path: root/src/OpenID/OpenIdProviderWebForms/Code/Util.cs
diff options
context:
space:
mode:
authorDavid Christiansen <coding@davedoes.net>2012-06-30 16:06:46 -0700
committerDavid Christiansen <coding@davedoes.net>2012-06-30 16:06:46 -0700
commit06401bb049dc29cf4446eb61a4a72317a644ce54 (patch)
tree7c475929350b31b4b848a1faa57bd0d7cbbf512c /src/OpenID/OpenIdProviderWebForms/Code/Util.cs
parent02ce959db12fec57e846e5ebfa662cd0327ce69c (diff)
parent3286c37f3a967e7d142534df84604a66be9d176c (diff)
downloadDotNetOpenAuth.Samples-06401bb049dc29cf4446eb61a4a72317a644ce54.zip
DotNetOpenAuth.Samples-06401bb049dc29cf4446eb61a4a72317a644ce54.tar.gz
DotNetOpenAuth.Samples-06401bb049dc29cf4446eb61a4a72317a644ce54.tar.bz2
Merge pull request #1 from DavidChristiansen/master
Kachow!
Diffstat (limited to 'src/OpenID/OpenIdProviderWebForms/Code/Util.cs')
-rw-r--r--src/OpenID/OpenIdProviderWebForms/Code/Util.cs75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/OpenID/OpenIdProviderWebForms/Code/Util.cs b/src/OpenID/OpenIdProviderWebForms/Code/Util.cs
new file mode 100644
index 0000000..deff447
--- /dev/null
+++ b/src/OpenID/OpenIdProviderWebForms/Code/Util.cs
@@ -0,0 +1,75 @@
+//-----------------------------------------------------------------------
+// <copyright file="Util.cs" company="Outercurve Foundation">
+// Copyright (c) Outercurve Foundation. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace OpenIdProviderWebForms.Code {
+ using System;
+ 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() {
+ return BuildIdentityUrl(HttpContext.Current.User.Identity.Name);
+ }
+
+ 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.aspx/" + 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;
+ }
+
+ if (idrequest.IsAuthenticated.Value) {
+ // add extension responses here.
+ }
+ } else {
+ HttpContext.Current.Response.Redirect("~/decide.aspx", true);
+ }
+ }
+
+ internal static void ProcessAnonymousRequest(IAnonymousRequest request) {
+ if (request.Immediate) {
+ // 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.
+ request.IsApproved = HttpContext.Current.User.Identity.IsAuthenticated;
+
+ if (request.IsApproved.Value) {
+ // Add extension responses here.
+ // These would typically be filled in from a user database
+ }
+ } else {
+ HttpContext.Current.Response.Redirect("~/decide.aspx", true);
+ }
+ }
+ }
+} \ No newline at end of file