blob: 198b8fa40130c02d4b8cca5a7327f5640b0ae37b (
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
36
37
|
namespace OpenIdProviderMvc.Models {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Routing;
using OpenIdProviderMvc.Code;
internal class User {
internal static Uri ClaimedIdentifierBaseUri {
get { return Util.GetAppPathRootedUri("user/"); }
}
internal static Uri GetClaimedIdentifierForUser(string username) {
if (String.IsNullOrEmpty(username)) {
throw new ArgumentNullException("username");
}
return new Uri(ClaimedIdentifierBaseUri, username.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));
}
}
}
|