diff --git a/src/Owin.Security.Providers.SlackProvider/Provider/SlackAuthenticatedContext.cs b/src/Owin.Security.Providers.SlackProvider/Provider/SlackAuthenticatedContext.cs index 6967b14..086def2 100644 --- a/src/Owin.Security.Providers.SlackProvider/Provider/SlackAuthenticatedContext.cs +++ b/src/Owin.Security.Providers.SlackProvider/Provider/SlackAuthenticatedContext.cs @@ -16,7 +16,8 @@ namespace Owin.Security.Providers.Slack.Provider /// The JSON-serialized user /// Slack Access token /// Indicates access level of application - public SlackAuthenticatedContext(IOwinContext context, JObject user, string accessToken, string scope) + /// Contains channel infomation about the choosen default channel + public SlackAuthenticatedContext(IOwinContext context, JObject user, string accessToken, string scope, JObject incomingWebhook) : base(context) { User = user; @@ -28,6 +29,14 @@ namespace Owin.Security.Providers.Slack.Provider TeamId = TryGetValue(user, "team_id"); TeamName = TryGetValue(user, "team"); TeamUrl = TryGetValue(user, "url"); + if (incomingWebhook != null) + { + ChannelId = TryGetValue(incomingWebhook, "channel_id"); + ChannelName = TryGetValue(incomingWebhook, "channel"); + ConfigurationUrl = TryGetValue(incomingWebhook, "configuration_url"); + HooksUrl = TryGetValue(incomingWebhook, "url"); + } + } /// @@ -73,6 +82,27 @@ namespace Owin.Security.Providers.Slack.Provider /// public string UserName { get; private set; } + + /// + /// Gets the name of the channel choose at oauth time + /// + public string ChannelName { get; private set; } + + /// + /// Gets the channel ID of the channel choosen at oauth time + /// + public string ChannelId { get; private set; } + + /// + /// Gets the confiquration url + /// + public string ConfigurationUrl { get; private set; } + + /// + /// Gets the hook url + /// + public string HooksUrl { get; private set; } + /// /// Gets the representing the user /// diff --git a/src/Owin.Security.Providers.SlackProvider/SlackAuthenticationHandler.cs b/src/Owin.Security.Providers.SlackProvider/SlackAuthenticationHandler.cs index 1b50b23..012048e 100644 --- a/src/Owin.Security.Providers.SlackProvider/SlackAuthenticationHandler.cs +++ b/src/Owin.Security.Providers.SlackProvider/SlackAuthenticationHandler.cs @@ -95,7 +95,7 @@ namespace Owin.Security.Providers.Slack dynamic response = JsonConvert.DeserializeObject(text); var accessToken = (string)response.access_token; var scope = (string)response.scope; - + var incomingWebhookChannelInfo = response.incoming_webhook; // Get the Slack user var userRequest = new HttpRequestMessage(HttpMethod.Get, UserInfoEndpoint + "?token=" + Uri.EscapeDataString(accessToken)); @@ -104,7 +104,7 @@ namespace Owin.Security.Providers.Slack text = await userResponse.Content.ReadAsStringAsync(); var user = JObject.Parse(text); - var context = new SlackAuthenticatedContext(Context, user, accessToken, scope) + var context = new SlackAuthenticatedContext(Context, user, accessToken, scope, incomingWebhookChannelInfo) { Identity = new ClaimsIdentity( Options.AuthenticationType, @@ -131,6 +131,10 @@ namespace Owin.Security.Providers.Slack { context.Identity.AddClaim(new Claim(ClaimTypes.Webpage, context.TeamUrl, XmlSchemaString, Options.AuthenticationType)); } + if (!string.IsNullOrEmpty(context.ChannelId)) + { + context.Identity.AddClaim(new Claim("urn:slack:channel_id", context.ChannelId, XmlSchemaString, Options.AuthenticationType)); + } context.Properties = properties; await Options.Provider.Authenticated(context);