Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement OmniAuth skip_info option #20

Merged
merged 1 commit into from
Jan 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions lib/omniauth/strategies/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,48 @@ class Slack < OmniAuth::Strategies::OAuth2
uid { raw_info['user_id'] }

info do
{
name: user_info['user'].to_h['profile'].to_h['real_name_normalized'],
email: user_info['user'].to_h['profile'].to_h['email'],
hash = {
nickname: raw_info['user'],
first_name: user_info['user'].to_h['profile'].to_h['first_name'],
last_name: user_info['user'].to_h['profile'].to_h['last_name'],
description: user_info['user'].to_h['profile'].to_h['title'],
image_24: user_info['user'].to_h['profile'].to_h['image_24'],
image_48: user_info['user'].to_h['profile'].to_h['image_48'],
image: user_info['user'].to_h['profile'].to_h['image_192'],
team: raw_info['team'],
user: raw_info['user'],
team_id: raw_info['team_id'],
team_domain: team_info['team'].to_h['domain'],
user_id: raw_info['user_id'],
is_admin: user_info['user'].to_h['is_admin'],
is_owner: user_info['user'].to_h['is_owner'],
time_zone: user_info['user'].to_h['tz']
user_id: raw_info['user_id']
}

unless skip_info?
hash.merge!(
name: user_info['user'].to_h['profile'].to_h['real_name_normalized'],
email: user_info['user'].to_h['profile'].to_h['email'],
first_name: user_info['user'].to_h['profile'].to_h['first_name'],
last_name: user_info['user'].to_h['profile'].to_h['last_name'],
description: user_info['user'].to_h['profile'].to_h['title'],
image_24: user_info['user'].to_h['profile'].to_h['image_24'],
image_48: user_info['user'].to_h['profile'].to_h['image_48'],
image: user_info['user'].to_h['profile'].to_h['image_192'],
team_domain: team_info['team'].to_h['domain'],
is_admin: user_info['user'].to_h['is_admin'],
is_owner: user_info['user'].to_h['is_owner'],
time_zone: user_info['user'].to_h['tz']
)
end

hash
end

extra do
{
hash = {
raw_info: raw_info,
user_info: user_info,
team_info: team_info,
web_hook_info: web_hook_info
}

unless skip_info?
hash.merge!(
user_info: user_info,
team_info: team_info
)
end

hash
end

def raw_info
Expand Down
15 changes: 15 additions & 0 deletions test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,18 @@ def setup
refute_has_key "refresh_token", strategy.credentials
end
end

class UserInfoTest < StrategyTestCase
test 'info should not include extended info when skip_info is specified' do
@options = { skip_info: true }
strategy.stubs(:raw_info).returns({})
assert_equal %w[nickname team user team_id user_id], strategy.info.keys.map(&:to_s)
end

test 'extra should not include extended info when skip_info is specified' do
@options = { skip_info: true }
strategy.stubs(:raw_info).returns({})
strategy.stubs(:webhook_info).returns({})
assert_equal %w[raw_info web_hook_info], strategy.extra.keys.map(&:to_s)
end
end