Skip to content
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Commit b4fadf8

Browse files
authored
Merge pull request #6 from koshilife/develop
release v0.1.1
2 parents 6364340 + 643b183 commit b4fadf8

File tree

8 files changed

+288
-78
lines changed

8 files changed

+288
-78
lines changed

.rubocop.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
AllCops:
2+
TargetRubyVersion: 2.6
3+
4+
Layout/AccessModifierIndentation:
5+
EnforcedStyle: outdent
6+
7+
Layout/HashAlignment:
8+
Enabled: false
9+
10+
Layout/DotPosition:
11+
EnforcedStyle: trailing
12+
13+
Layout/SpaceInsideHashLiteralBraces:
14+
EnforcedStyle: no_space
15+
16+
Lint/SuppressedException:
17+
Enabled: false
18+
19+
Metrics/BlockLength:
20+
Enabled: false
21+
22+
Metrics/BlockNesting:
23+
Max: 2
24+
25+
Layout/LineLength:
26+
AllowURI: true
27+
Enabled: false
28+
29+
Metrics/MethodLength:
30+
CountComments: false
31+
Max: 15
32+
33+
Metrics/ParameterLists:
34+
Max: 4
35+
CountKeywordArgs: true
36+
37+
Metrics/AbcSize:
38+
Enabled: false
39+
40+
Style/CollectionMethods:
41+
PreferredMethods:
42+
map: 'collect'
43+
reduce: 'inject'
44+
find: 'detect'
45+
find_all: 'select'
46+
47+
Style/Documentation:
48+
Enabled: false
49+
50+
Style/DoubleNegation:
51+
Enabled: false
52+
53+
Style/EachWithObject:
54+
Enabled: false
55+
56+
Style/Encoding:
57+
Enabled: false
58+
59+
Style/ExpandPathArguments:
60+
Enabled: false
61+
62+
Style/HashSyntax:
63+
EnforcedStyle: hash_rockets
64+
65+
Style/Lambda:
66+
Enabled: false
67+
68+
Style/RaiseArgs:
69+
EnforcedStyle: compact

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.1.1
2+
3+
- refs #4 Add tests and make code coverage 100%.
4+
15
# 0.1.0
26

37
- Initial release

README.md

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Next, tell OmniAuth about this provider. For a Rails app, your `config/initializ
3131

3232
```ruby
3333
Rails.application.config.middleware.use OmniAuth::Builder do
34-
zoom_scopes = %i[user:read meeting:read meeting:write]
34+
zoom_scopes = %i[user_profile meeting:write]
3535
provider :zoom, zoom_client_id, zoom_client_secret, :scope => zoom_scopes.join(',')
3636
end
3737
```
@@ -44,49 +44,45 @@ The auth hash `request.env['omniauth.auth']` would look like this:
4444

4545
```js
4646
{
47-
"result": {
48-
"provider": "zoom",
49-
"uid": "KdYKjnimT4KPd8FFgQt9FQ",
50-
"info": {},
51-
"credentials": {
52-
"token": "ACCESS_TOKEN",
53-
"refresh_token": "REFRESH_TOKEN",
54-
"expires_at": 1594035991,
55-
"expires": true
56-
},
57-
"extra": {
58-
"raw_info": {
59-
"id": "KdYKjnimT4KPd8FFgQt9FQ",
60-
"first_name": "Jane",
61-
"last_name": "Dev",
62-
"email": "jane.dev@email.com",
63-
"type": 2,
64-
"role_name": "Owner",
65-
"pmi": 1234567890,
66-
"use_pmi": false,
67-
"vanity_url": "https://janedevinc.zoom.us/my/janedev",
68-
"personal_meeting_url": "https://janedevinc.zoom.us/j/1234567890",
69-
"timezone": "America/Denver",
70-
"verified": 1,
71-
"dept": "",
72-
"created_at": "2019-04-05T15:24:32Z",
73-
"last_login_time": "2019-12-16T18:02:48Z",
74-
"last_client_version": "4.6.12611.1124(mac)",
75-
"pic_url": "https://janedev.zoom.us/p/KdYKjnimFR5Td8KKdQt9FQ/19f6430f-ca72-4154-8998-ede6be4542c7-837",
76-
"host_key": "533895",
77-
"jid": "kdykjnimt4kpd8kkdqt9fq@xmpp.zoom.us",
78-
"group_ids": [],
79-
"im_group_ids": [
80-
"3NXCD9VFTCOUH8LD-QciGw"
81-
],
82-
"account_id": "gVcjZnYYRLDbb_MfgHuaxg",
83-
"language": "en-US",
84-
"phone_country": "US",
85-
"phone_number": "+1 1234567891",
86-
"status": "active"
87-
}
88-
}
47+
"provider": "zoom",
48+
"uid": "KdYKjnimT4KPd8FFgQt9FQ",
49+
"info": {},
50+
"credentials": {
51+
"token": "ACCESS_TOKEN",
52+
"refresh_token": "REFRESH_TOKEN",
53+
"expires_at": 1594035991,
54+
"expires": true
55+
},
56+
"extra": {
57+
"raw_info": {
58+
"id": "KdYKjnimT4KPd8FFgQt9FQ",
59+
"first_name": "Jane",
60+
"last_name": "Dev",
61+
"email": "jane.dev@email.com",
62+
"type": 2,
63+
"role_name": "Owner",
64+
"pmi": 1234567890,
65+
"use_pmi": false,
66+
"vanity_url": "https://janedevinc.zoom.us/my/janedev",
67+
"personal_meeting_url": "https://janedevinc.zoom.us/j/1234567890",
68+
"timezone": "America/Denver",
69+
"verified": 1,
70+
"dept": "",
71+
"created_at": "2019-04-05T15:24:32Z",
72+
"last_login_time": "2019-12-16T18:02:48Z",
73+
"last_client_version": "4.6.12611.1124(mac)",
74+
"pic_url": "https://janedev.zoom.us/p/KdYKjnimFR5Td8KKdQt9FQ/19f6430f-ca72-4154-8998-ede6be4542c7-837",
75+
"host_key": "533895",
76+
"jid": "kdykjnimt4kpd8kkdqt9fq@xmpp.zoom.us",
77+
"group_ids": [],
78+
"im_group_ids": ["3NXCD9VFTCOUH8LD-QciGw"],
79+
"account_id": "gVcjZnYYRLDbb_MfgHuaxg",
80+
"language": "en-US",
81+
"phone_country": "US",
82+
"phone_number": "+1 1234567891",
83+
"status": "active"
8984
}
85+
}
9086
}
9187
```
9288

lib/omniauth-zoom/version.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

3-
module Omniauth
3+
module OmniAuth
44
module Zoom
5-
VERSION = '0.1.0'
5+
VERSION = '0.1.1'
66
end
77
end

lib/omniauth/strategies/zoom.rb

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,44 @@
66

77
module OmniAuth
88
module Strategies
9+
# OmniAuth strategy for zoom.us
910
class Zoom < OmniAuth::Strategies::OAuth2
1011
option :name, 'zoom'
11-
option :client_options, site: 'https://zoom.us'
12+
option :client_options, :site => 'https://zoom.us'
1213

13-
uid { raw_info[:id] }
14+
uid { raw_info['id'] }
15+
extra { {:raw_info => raw_info} }
1416

15-
extra do
16-
{ raw_info: raw_info }
17-
end
18-
19-
protected
17+
protected
2018

2119
def build_access_token
2220
params = {
23-
grant_type: 'authorization_code',
24-
code: request.params['code'],
25-
redirect_uri: callback_url
21+
:grant_type => 'authorization_code',
22+
:code => request.params['code'],
23+
:redirect_uri => callback_url
2624
}
27-
path = "#{client.options[:token_url]}?#{params.to_query}"
28-
token = Base64.strict_encode64("#{client.id}:#{client.secret}")
29-
opts = { headers: { Authorization: "Basic #{token}" } }
30-
31-
response = client.request(:post, path, opts)
32-
access_token_opts = response.parsed.merge(deep_symbolize(options.auth_token_params))
33-
::OAuth2::AccessToken.from_hash(client, access_token_opts).tap do |access_token|
34-
if access_token.respond_to?(:response=)
35-
access_token.response = response
36-
end
37-
end
38-
end
25+
path = "#{client.options[:token_url]}?#{URI.encode_www_form(params)}"
26+
headers_secret = Base64.strict_encode64("#{client.id}:#{client.secret}")
27+
opts = {:headers => {:Authorization => "Basic #{headers_secret}"}}
3928

40-
def callback_url
41-
full_host + script_name + callback_path
29+
res = client.request(:post, path, opts)
30+
::OAuth2::AccessToken.from_hash(client, res.parsed)
4231
end
4332

33+
private
34+
4435
def raw_info
45-
return @raw_info unless @raw_info.nil?
36+
return @raw_info if defined?(@raw_info)
4637

47-
res = access_token.get('/v2/users/me')
48-
@raw_info = JSON.parse(res.body, symbolize_names: true)
38+
@raw_info = access_token.get('/v2/users/me').parsed || {}
4939
rescue StandardError => e
50-
logger = OmniAuth.config.logger
51-
logger&.debug("#{self.class}.#{__method__} #{e.class} occured. message:#{e.message}")
40+
log(:error, "#{e.class} occured. message:#{e.message}")
5241
@raw_info = {}
5342
end
43+
44+
def callback_url
45+
full_host + script_name + callback_path
46+
end
5447
end
5548
end
5649
end

omniauth-zoom.gemspec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require_relative 'lib/omniauth-zoom/version'
44

55
Gem::Specification.new do |spec|
66
spec.name = 'omniauth-zoom'
7-
spec.version = Omniauth::Zoom::VERSION
7+
spec.version = OmniAuth::Zoom::VERSION
88
spec.authors = ['Kenji Koshikawa']
99
spec.email = ['koshikawa2009@gmail.com']
1010

@@ -35,6 +35,9 @@ Gem::Specification.new do |spec|
3535
spec.add_development_dependency 'codecov', '~> 0.1.17'
3636
spec.add_development_dependency 'minitest', '~> 5.14.1'
3737
spec.add_development_dependency 'minitest-reporters', '~> 1.4.2'
38+
spec.add_development_dependency 'omniauth', '~> 1.9.1'
39+
spec.add_development_dependency 'rack-test', '~> 1.1.0'
3840
spec.add_development_dependency 'rake', '~> 13.0'
3941
spec.add_development_dependency 'simplecov', '~> 0.18.5'
42+
spec.add_development_dependency 'webmock', '~> 3.7.6'
4043
end

test/omniauth/zoom_test.rb

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,59 @@
22

33
require 'test_helper'
44

5-
class Omniauth::ZoomTest < Minitest::Test
6-
def test_that_it_has_a_version_number
7-
refute_nil ::Omniauth::Zoom::VERSION
5+
class StrategyZoomTest < StrategyTest
6+
def test_it_has_a_version_number
7+
refute_nil ::OmniAuth::Zoom::VERSION
8+
end
9+
10+
def test_it_has_a_client_options
11+
args = [@client_id, @client_secret, @options]
12+
strat = OmniAuth::Strategies::Zoom.new(nil, *args)
13+
assert_equal(@client_id, strat.options[:client_id])
14+
assert_equal(@client_secret, strat.options[:client_secret])
15+
assert_equal(@scope, strat.options[:scope])
16+
assert_equal('https://zoom.us', strat.options[:client_options][:site])
17+
end
18+
19+
def test_it_returns_auth_hash_in_callback_phase
20+
add_mock_exchange_token
21+
add_mock_user_info
22+
post '/auth/zoom/callback', :code => @authorization_code, :state => 'state123'
23+
24+
actual_auth = auth_hash.to_hash
25+
assert(!actual_auth['credentials'].delete('expires_at').nil?)
26+
expected_auth = {
27+
'provider' => 'zoom',
28+
'uid' => dummy_user_info_response[:id],
29+
'info' => {'name' => nil},
30+
'credentials' => {'token' => 'DUMMY_TOKEN', 'refresh_token' => 'DUMMY_REFRESH_TOKEN', 'expires' => true},
31+
'extra' => {
32+
'raw_info' => JSON.parse(dummy_user_info_response.to_json)
33+
}
34+
}
35+
assert_equal(expected_auth, actual_auth)
36+
end
37+
38+
def test_it_returns_auth_hash_in_case_of_failure_of_get_user_info_in_callbach_phase
39+
add_mock_exchange_token
40+
add_mock_user_info_then_fail
41+
post '/auth/zoom/callback', :code => @authorization_code, :state => 'state123'
42+
43+
actual_auth = auth_hash.to_hash
44+
assert(!actual_auth['credentials'].delete('expires_at').nil?)
45+
expected_auth = {
46+
'provider' => 'zoom',
47+
'uid' => nil,
48+
'info' => {'name' => nil},
49+
'credentials' => {'token' => 'DUMMY_TOKEN', 'refresh_token' => 'DUMMY_REFRESH_TOKEN', 'expires' => true},
50+
'extra' => {'raw_info' => {}}
51+
}
52+
assert_equal(expected_auth, actual_auth)
53+
end
54+
55+
private
56+
57+
def auth_hash
58+
last_request.env['omniauth.auth']
859
end
960
end

0 commit comments

Comments
 (0)