forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthUserSession.cs
More file actions
91 lines (63 loc) · 2.64 KB
/
AuthUserSession.cs
File metadata and controls
91 lines (63 loc) · 2.64 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.Linq;
namespace ServiceStack.ServiceInterface.Auth
{
public class AuthUserSession : IAuthSession
{
public AuthUserSession()
{
this.ProviderOAuthAccess = new List<IOAuthTokens>();
}
public string ReferrerUrl { get; set; }
public string Id { get; set; }
public string UserAuthId { get; set; }
public string UserAuthName { get; set; }
public string UserName { get; set; }
public string TwitterUserId { get; set; }
public string TwitterScreenName { get; set; }
public string FacebookUserId { get; set; }
public string FacebookUserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string DisplayName { get; set; }
public string Email { get; set; }
public string PrimaryEmail { get; set; }
public string RequestTokenSecret { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime LastModified { get; set; }
public List<IOAuthTokens> ProviderOAuthAccess { get; set; }
public List<string> Roles { get; set; }
public List<string> Permissions { get; set; }
public virtual bool IsAuthenticated { get; set; }
public virtual string Sequence { get; set; }
public virtual bool IsAuthorized(string provider)
{
var tokens = ProviderOAuthAccess.FirstOrDefault(x => x.Provider == provider);
return AuthService.GetAuthProvider(provider).IsAuthorizedSafe(this, tokens);
}
public virtual bool HasPermission(string permission)
{
return this.Permissions != null && this.Permissions.Contains(permission);
}
public virtual bool HasRole(string role)
{
return this.Roles != null && this.Roles.Contains(role);
}
public virtual void OnAuthenticated(IServiceBase authService, IAuthSession session, IOAuthTokens tokens, Dictionary<string, string> authInfo)
{
}
}
public static class AuthSessionExtensions
{
public static IOAuthTokens GetOAuthTokens(this IAuthSession session, string provider)
{
foreach (var tokens in session.ProviderOAuthAccess)
{
if (string.Compare(tokens.Provider, provider, StringComparison.InvariantCultureIgnoreCase) == 0)
return tokens;
}
return null;
}
}
}