From ceec1c64630da20b9acb4777e6f80251ab43d15f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Wed, 29 Aug 2018 17:05:55 +0200 Subject: [PATCH 1/4] support workspace apps --- lib/omniauth/strategies/slack.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/omniauth/strategies/slack.rb b/lib/omniauth/strategies/slack.rb index 3d5a2d6..c46cde1 100644 --- a/lib/omniauth/strategies/slack.rb +++ b/lib/omniauth/strategies/slack.rb @@ -22,7 +22,7 @@ class Slack < OmniAuth::Strategies::OAuth2 # User ID is not guaranteed to be globally unique across all Slack users. # The combination of user ID and team ID, on the other hand, is guaranteed # to be globally unique. - uid { "#{user_identity['id']}-#{team_identity['id']}" } + uid { "#{user_id}-#{team_id}" } info do hash = { @@ -49,7 +49,8 @@ class Slack < OmniAuth::Strategies::OAuth2 user_info: user_info, # Requires the users:read scope team_info: team_info, # Requires the team:read scope web_hook_info: web_hook_info, - bot_info: bot_info + bot_info: bot_info, + workspace_info: workspace_info } } end @@ -98,7 +99,20 @@ def bot_info access_token.params['bot'] end + def workspace_info + return {} unless access_token.params.key? 'team_id' + access_token.params.except(['ok', 'access_token', 'token_type']) + end + private + + def user_id + user_identity['id'].presence || workspace_info['authorizing_user_id'].presence + end + + def team_id + team_identity['id'].presence || workspace_info['team_id'].presence + end def callback_url full_host + script_name + callback_path From 6a8fac569ec6a4f0c1932c4c24e6a5baa8aafab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20J=C3=A4ger?= Date: Wed, 29 Aug 2018 18:14:55 +0200 Subject: [PATCH 2/4] Update omniauth-slack.gemspec --- omniauth-slack.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omniauth-slack.gemspec b/omniauth-slack.gemspec index 2474bf0..9d3cc56 100644 --- a/omniauth-slack.gemspec +++ b/omniauth-slack.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.add_runtime_dependency 'omniauth-oauth2', "~> 1.4" + spec.add_runtime_dependency 'omniauth-oauth2', "~> 1.3.1" spec.add_development_dependency "bundler", "~> 1.11.2" spec.add_development_dependency "rake" From 4495dc743e6e169731e9a4be980ca004049698e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Wed, 29 Aug 2018 18:42:28 +0200 Subject: [PATCH 3/4] adapt to new structure --- lib/omniauth/strategies/slack.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/omniauth/strategies/slack.rb b/lib/omniauth/strategies/slack.rb index c46cde1..e2b3fca 100644 --- a/lib/omniauth/strategies/slack.rb +++ b/lib/omniauth/strategies/slack.rb @@ -107,7 +107,7 @@ def workspace_info private def user_id - user_identity['id'].presence || workspace_info['authorizing_user_id'].presence + user_identity['id'].presence || workspace_info.dig('authorizing_user', 'user_id').presence end def team_id From a4bf8a4e49d8e056936923b0e99d7bf6988aba53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Ja=CC=88ger?= Date: Mon, 28 Jan 2019 18:03:12 +0100 Subject: [PATCH 4/4] update dependency requirements for omniauth-oauth2 --- omniauth-slack.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omniauth-slack.gemspec b/omniauth-slack.gemspec index 9d3cc56..2474bf0 100644 --- a/omniauth-slack.gemspec +++ b/omniauth-slack.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.add_runtime_dependency 'omniauth-oauth2', "~> 1.3.1" + spec.add_runtime_dependency 'omniauth-oauth2', "~> 1.4" spec.add_development_dependency "bundler", "~> 1.11.2" spec.add_development_dependency "rake"