Skip to content

Commit

Permalink
Merge branch 'gssbzn-slack-button'
Browse files Browse the repository at this point in the history
  • Loading branch information
kmrshntr committed Sep 11, 2015
2 parents 1537dfb + c086cac commit aae332a
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 aae332a

Please sign in to comment.