blob: 577aa059b5a0b7bfc730e722c7d8df77ecff17b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
namespace OpenIdProviderMvc.Models {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Routing;
internal class User {
internal static Uri GetClaimedIdentifierForUser(string username) {
string appPath = HttpContext.Current.Request.ApplicationPath;
if (!appPath.EndsWith("/")) {
appPath += "/";
}
Uri claimedIdentifier = new Uri(
HttpContext.Current.Request.Url,
appPath + "user/" + username);
return new Uri(claimedIdentifier.AbsoluteUri.ToLowerInvariant());
}
internal static string GetUserFromClaimedIdentifier(Uri claimedIdentifier) {
Regex regex = new Regex(@"/user/([^/\?]+)");
Match m = regex.Match(claimedIdentifier.AbsoluteUri);
if (!m.Success) {
throw new ArgumentException();
}
return m.Groups[1].Value;
}
internal static Uri GetNormalizedClaimedIdentifier(Uri uri) {
return GetClaimedIdentifierForUser(GetUserFromClaimedIdentifier(uri));
}
}
}
|