Skip to content

Commit 5cfc15d

Browse files
chunkychodekevinchalet
authored andcommitted
Update the Slack provider to support the bot/webhook claims
1 parent 025a5a0 commit 5cfc15d

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/AspNet.Security.OAuth.Slack/SlackAuthenticationHandler.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync([NotNull]
4242
}
4343

4444
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
45-
45+
4646
identity.AddOptionalClaim(ClaimTypes.NameIdentifier, SlackAuthenticationHelper.GetUserIdentifier(payload), Options.ClaimsIssuer)
4747
.AddOptionalClaim(ClaimTypes.Name, SlackAuthenticationHelper.GetUserName(payload), Options.ClaimsIssuer)
4848
.AddOptionalClaim("urn:slack:team_id", SlackAuthenticationHelper.GetTeamIdentifier(payload), Options.ClaimsIssuer)
4949
.AddOptionalClaim("urn:slack:team_name", SlackAuthenticationHelper.GetTeamName(payload), Options.ClaimsIssuer)
50-
.AddOptionalClaim("urn:slack:team_url", SlackAuthenticationHelper.GetTeamLink(payload), Options.ClaimsIssuer);
50+
.AddOptionalClaim("urn:slack:team_url", SlackAuthenticationHelper.GetTeamLink(payload), Options.ClaimsIssuer)
51+
.AddOptionalClaim("urn:slack:bot:user_id", SlackAuthenticationHelper.GetBotUserId(payload), Options.ClaimsIssuer)
52+
.AddOptionalClaim("urn:slack:bot:access_token", SlackAuthenticationHelper.GetBotAccessToken(payload), Options.ClaimsIssuer)
53+
.AddOptionalClaim("urn:slack:webhook:channel", SlackAuthenticationHelper.GetWebhookChannel(payload), Options.ClaimsIssuer)
54+
.AddOptionalClaim("urn:slack:webhook:url", SlackAuthenticationHelper.GetWebhookURL(payload), Options.ClaimsIssuer)
55+
.AddOptionalClaim("urn:slack:webhook:configuration_url", SlackAuthenticationHelper.GetWebhookConfigurationURL(payload), Options.ClaimsIssuer);
5156

5257
var principal = new ClaimsPrincipal(identity);
5358
var ticket = new AuthenticationTicket(principal, properties, Options.AuthenticationScheme);

src/AspNet.Security.OAuth.Slack/SlackAuthenticationHelper.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,31 @@ public static class SlackAuthenticationHelper {
3737
/// Gets the URL corresponding to the authenticated user.
3838
/// </summary>
3939
public static string GetTeamLink([NotNull] JObject user) => user.Value<string>("url");
40+
41+
/// <summary>
42+
/// Gets the identifier associated with the bot.
43+
/// </summary>
44+
public static string GetBotUserId([NotNull] JObject user) => user["bot"]?.Value<string>("bot_user_id");
45+
46+
/// <summary>
47+
/// Gets the access token associated with the bot.
48+
/// </summary>
49+
public static string GetBotAccessToken([NotNull] JObject user) => user["bot"]?.Value<string>("bot_access_token");
50+
51+
/// <summary>
52+
/// Gets the channel name of the selected webhook.
53+
/// </summary>
54+
public static string GetWebhookChannel([NotNull] JObject user) => user["incoming_webhook"]?.Value<string>("channel");
55+
56+
/// <summary>
57+
/// Gets the URL of the selected webhook.
58+
/// </summary>
59+
public static string GetWebhookURL([NotNull] JObject user) => user["incoming_webhook"]?.Value<string>("url");
60+
61+
/// <summary>
62+
/// Gets the channel configuration URL of the selected webhook.
63+
/// </summary>
64+
public static string GetWebhookConfigurationURL([NotNull] JObject user) => user["incoming_webhook"]?.Value<string>("configuration_url");
65+
4066
}
4167
}

0 commit comments

Comments
 (0)