Skip to content

Commit

Permalink
Add extra infor for when scope is incoming-webhook
Browse files Browse the repository at this point in the history
Slack just added a new scope that allows easy creation of incoming webhooks on authorization, this changes to the strategy allows it to return the new info slack provides to the client about the created webhook
  • Loading branch information
Gustavo Bazan committed Sep 11, 2015
1 parent 1537dfb commit c086cac
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ test/tmp
test/version_tmp
tmp
.idea/
.ruby-version
.ruby-gemset
2 changes: 1 addition & 1 deletion lib/omniauth-slack.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require 'omniauth-slack/version'
require 'omniauth/strategies/slack'
require 'omniauth/strategies/slack'
34 changes: 25 additions & 9 deletions lib/omniauth/strategies/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
module OmniAuth
module Strategies
class Slack < OmniAuth::Strategies::OAuth2
option :name, 'slack'

option :name, "slack"

option :authorize_options, [ :scope, :team ]
option :authorize_options, [:scope, :team]

option :client_options, {
site: "https://slack.com",
token_url: "/api/oauth.access"
site: 'https://slack.com',
token_url: '/api/oauth.access'
}

option :auth_token_params, {
Expand Down Expand Up @@ -43,19 +42,36 @@ class Slack < OmniAuth::Strategies::OAuth2
end

extra do
{:raw_info => raw_info, :user_info => user_info, :team_info => team_info}
{
raw_info: raw_info,
user_info: user_info,
team_info: team_info,
web_hook_info: web_hook_info
}
end

def raw_info
@raw_info ||= access_token.get('/api/auth.test').parsed
end

def user_info
@user_info ||= access_token.get("/api/users.info?user=#{raw_info['user_id']}").parsed
end

def team_info
@team_info ||= access_token.get("/api/team.info").parsed
@team_info ||= access_token.get('/api/team.info').parsed
end

def raw_info
@raw_info ||= access_token.get("/api/auth.test").parsed
def web_hook_info
return {} unless incoming_webhook_allowed?
access_token.params['incoming_webhook']
end

def incoming_webhook_allowed?
return false unless options['scope']
webhooks_scopes = ['incoming-webhook']
scopes = options['scope'].split(',')
(scopes & webhooks_scopes).any?
end
end
end
Expand Down

0 comments on commit c086cac

Please sign in to comment.