@@ -17,133 +17,86 @@ namespace AspNet.Security.OAuth.Slack
17
17
public static class SlackAuthenticationHelper
18
18
{
19
19
/// <summary>
20
- /// Gets the identifier corresponding to the authenticated user.
21
- /// </summary>
22
- public static string GetUserIdentifier ( [ NotNull ] JObject user )
23
- {
24
- if ( user == null )
25
- {
26
- throw new ArgumentNullException ( nameof ( user ) ) ;
27
- }
28
-
29
- return user . Value < string > ( "user_id" ) ;
30
- }
31
-
32
- /// <summary>
33
- /// Gets the login corresponding to the authenticated user.
34
- /// </summary>
35
- public static string GetUserName ( [ NotNull ] JObject user )
36
- {
37
- if ( user == null )
38
- {
39
- throw new ArgumentNullException ( nameof ( user ) ) ;
40
- }
41
-
42
- return user . Value < string > ( "user" ) ;
43
- }
44
-
45
- /// <summary>
46
- /// Gets the name corresponding to the authenticated user.
47
- /// </summary>
48
- public static string GetTeamIdentifier ( [ NotNull ] JObject user )
49
- {
50
- if ( user == null )
51
- {
52
- throw new ArgumentNullException ( nameof ( user ) ) ;
53
- }
54
-
55
- return user . Value < string > ( "team_id" ) ;
56
- }
57
-
58
- /// <summary>
59
- /// Gets the name corresponding to the authenticated user.
60
- /// </summary>
61
- public static string GetTeamName ( [ NotNull ] JObject user )
62
- {
63
- if ( user == null )
64
- {
65
- throw new ArgumentNullException ( nameof ( user ) ) ;
66
- }
67
-
68
- return user . Value < string > ( "team" ) ;
69
- }
70
-
71
- /// <summary>
72
- /// Gets the URL corresponding to the authenticated user.
20
+ /// Gets a unique identifer for the authenticated user.
73
21
/// </summary>
74
- public static string GetTeamLink ( [ NotNull ] JObject user )
22
+ /// <remarks>
23
+ /// Note: according to the Slack API documentation (https://api.slack.com/methods/users.identity),
24
+ /// user identifiers are not guaranteed to be globally unique across teams. The combination of
25
+ /// the user and team identifiers on the other hand, is guaranteed to be globally unique.
26
+ /// </remarks>
27
+ public static string GetUniqueIdentifier ( [ NotNull ] JObject user )
75
28
{
76
29
if ( user == null )
77
30
{
78
31
throw new ArgumentNullException ( nameof ( user ) ) ;
79
32
}
80
33
81
- return user . Value < string > ( "url" ) ;
34
+ return string . Concat ( GetTeamIdentifier ( user ) , "|" , GetUserIdentifier ( user ) ) ;
82
35
}
83
36
84
37
/// <summary>
85
- /// Gets the identifier associated with the bot .
38
+ /// Gets the email address corresponding to the authenticated user .
86
39
/// </summary>
87
- public static string GetBotUserId ( [ NotNull ] JObject user )
40
+ public static string GetUserEmail ( [ NotNull ] JObject user )
88
41
{
89
42
if ( user == null )
90
43
{
91
44
throw new ArgumentNullException ( nameof ( user ) ) ;
92
45
}
93
46
94
- return user [ "bot" ] ? . Value < string > ( "bot_user_id " ) ;
47
+ return user . Value < JObject > ( "user" ) ? . Value < string > ( "email " ) ;
95
48
}
96
49
97
50
/// <summary>
98
- /// Gets the access token associated with the bot .
51
+ /// Gets the identifier corresponding to the authenticated user .
99
52
/// </summary>
100
- public static string GetBotAccessToken ( [ NotNull ] JObject user )
53
+ public static string GetUserIdentifier ( [ NotNull ] JObject user )
101
54
{
102
55
if ( user == null )
103
56
{
104
57
throw new ArgumentNullException ( nameof ( user ) ) ;
105
58
}
106
59
107
- return user [ "bot" ] ? . Value < string > ( "bot_access_token " ) ;
60
+ return user . Value < JObject > ( "user" ) ? . Value < string > ( "id " ) ;
108
61
}
109
62
110
63
/// <summary>
111
- /// Gets the channel name of the selected webhook .
64
+ /// Gets the login corresponding to the authenticated user .
112
65
/// </summary>
113
- public static string GetWebhookChannel ( [ NotNull ] JObject user )
66
+ public static string GetUserName ( [ NotNull ] JObject user )
114
67
{
115
68
if ( user == null )
116
69
{
117
70
throw new ArgumentNullException ( nameof ( user ) ) ;
118
71
}
119
72
120
- return user [ "incoming_webhook" ] ? . Value < string > ( "channel " ) ;
73
+ return user . Value < JObject > ( "user" ) ? . Value < string > ( "name " ) ;
121
74
}
122
75
123
76
/// <summary>
124
- /// Gets the URL of the selected webhook .
77
+ /// Gets the name corresponding to the authenticated user .
125
78
/// </summary>
126
- public static string GetWebhookURL ( [ NotNull ] JObject user )
79
+ public static string GetTeamIdentifier ( [ NotNull ] JObject user )
127
80
{
128
81
if ( user == null )
129
82
{
130
83
throw new ArgumentNullException ( nameof ( user ) ) ;
131
84
}
132
85
133
- return user [ "incoming_webhook" ] ? . Value < string > ( "url " ) ;
86
+ return user . Value < JObject > ( "team" ) ? . Value < string > ( "id " ) ;
134
87
}
135
88
136
89
/// <summary>
137
- /// Gets the channel configuration URL of the selected webhook .
90
+ /// Gets the name corresponding to the authenticated user .
138
91
/// </summary>
139
- public static string GetWebhookConfigurationURL ( [ NotNull ] JObject user )
92
+ public static string GetTeamName ( [ NotNull ] JObject user )
140
93
{
141
94
if ( user == null )
142
95
{
143
96
throw new ArgumentNullException ( nameof ( user ) ) ;
144
97
}
145
98
146
- return user [ "incoming_webhook" ] ? . Value < string > ( "configuration_url " ) ;
99
+ return user . Value < JObject > ( "team" ) ? . Value < string > ( "name " ) ;
147
100
}
148
101
}
149
102
}
0 commit comments