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

Commit

Permalink
Merge pull request #13 from koshilife/develop
Browse files Browse the repository at this point in the history
release 0.2.1
  • Loading branch information
koshilife authored Sep 3, 2020
2 parents a71dfff + 084297c commit 674eee2
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 67 deletions.
20 changes: 11 additions & 9 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ Metrics/BlockNesting:
Max: 2

Layout/LineLength:
AllowURI: true
Enabled: false
Max: 120

Metrics/MethodLength:
CountComments: false
Max: 15
Max: 20

Metrics/ParameterLists:
Max: 4
Expand All @@ -39,10 +38,10 @@ Metrics/AbcSize:

Style/CollectionMethods:
PreferredMethods:
map: 'collect'
reduce: 'inject'
find: 'detect'
find_all: 'select'
map: "collect"
reduce: "inject"
find: "detect"
find_all: "select"

Style/Documentation:
Enabled: false
Expand All @@ -60,10 +59,13 @@ Style/ExpandPathArguments:
Enabled: false

Style/HashSyntax:
EnforcedStyle: hash_rockets
EnforcedStyle: ruby19

Style/Lambda:
Enabled: false

Style/RaiseArgs:
EnforcedStyle: compact
EnforcedStyle: compact

Style/AsciiComments:
Enabled: false
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# 0.2.0
# CHANGELOG

## 0.2.1

- fix rubocop warnings.

## 0.2.0

- refs #11 fix library dependencies.
- remove minitest-reporter.

# 0.1.2
## 0.1.2

- make the error handling when missing scope for reading user info better.

# 0.1.1
## 0.1.1

- refs #4 Add tests and make code coverage 100%.

# 0.1.0
## 0.1.0

- Initial release
14 changes: 8 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
require "bundler/gem_tasks"
require "rake/testtask"
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end

task :default => :test
task default: :test
2 changes: 1 addition & 1 deletion lib/omniauth-zoom/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module OmniAuth
module Zoom
VERSION = '0.2.0'
VERSION = '0.2.1'
end
end
12 changes: 6 additions & 6 deletions lib/omniauth/strategies/zoom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ module Strategies
# OmniAuth strategy for zoom.us
class Zoom < OmniAuth::Strategies::OAuth2
option :name, 'zoom'
option :client_options, :site => 'https://zoom.us'
option :client_options, site: 'https://zoom.us'

uid { raw_info['id'] }
extra { {:raw_info => raw_info} }
extra { {raw_info: raw_info} }

protected

def build_access_token
params = {
:grant_type => 'authorization_code',
:code => request.params['code'],
:redirect_uri => callback_url
grant_type: 'authorization_code',
code: request.params['code'],
redirect_uri: callback_url
}
path = "#{client.options[:token_url]}?#{URI.encode_www_form(params)}"
headers_secret = Base64.strict_encode64("#{client.id}:#{client.secret}")
opts = {:headers => {:Authorization => "Basic #{headers_secret}"}}
opts = {headers: {Authorization: "Basic #{headers_secret}"}}

res = client.request(:post, path, opts)
::OAuth2::AccessToken.from_hash(client, res.parsed)
Expand Down
6 changes: 3 additions & 3 deletions test/omniauth/zoom_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_it_has_a_client_options
def test_it_returns_auth_hash_in_callback_phase
add_mock_exchange_token
add_mock_user_info
post '/auth/zoom/callback', :code => @authorization_code, :state => 'state123'
post '/auth/zoom/callback', code: @authorization_code, state: 'state123'

actual_auth = auth_hash.to_hash
assert(!actual_auth['credentials'].delete('expires_at').nil?)
Expand All @@ -38,7 +38,7 @@ def test_it_returns_auth_hash_in_callback_phase
def test_it_returns_auth_hash_in_case_of_failure_of_get_user_info_in_callbach_phase
add_mock_exchange_token
add_mock_user_info_then_fail_because_of_missing_scope
post '/auth/zoom/callback', :code => @authorization_code, :state => 'state123'
post '/auth/zoom/callback', code: @authorization_code, state: 'state123'

actual_auth = auth_hash.to_hash
assert(!actual_auth['credentials'].delete('expires_at').nil?)
Expand All @@ -55,7 +55,7 @@ def test_it_returns_auth_hash_in_case_of_failure_of_get_user_info_in_callbach_ph
def test_it_does_not_return_auth_hash_in_case_of_unkonwn_failure_in_callbach_phase
add_mock_exchange_token
add_mock_user_info_then_fail_because_of_unknown
post '/auth/zoom/callback', :code => @authorization_code, :state => 'state123'
post '/auth/zoom/callback', code: @authorization_code, state: 'state123'
assert_nil(auth_hash)
end

Expand Down
76 changes: 38 additions & 38 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setup
@client_id = 'DUMMY_CLIENT_ID'
@client_secret = 'DUMMY_CLIENT_SECRET'
@scope = 'user_profile'
@options = {:scope => @scope, :provider_ignores_state => true}
@options = {scope: @scope, provider_ignores_state: true}
@authorization_code = 'DUMMY_AUTH_CODE'
@access_token = 'DUMMY_TOKEN'
@refresh_token = 'DUMMY_REFRESH_TOKEN'
Expand All @@ -43,16 +43,16 @@ def add_mock_exchange_token
secret = Base64.strict_encode64("#{@client_id}:#{@client_secret}")
headers = {'Authorization' => "Basic #{secret}"}
res_headers = {'Content-Type' => 'application/json'}
stub_request(:post, url).with(:headers => headers).to_return(:status => 200, :body => dummy_token_response.to_json, :headers => res_headers)
stub_request(:post, url).with(headers: headers).to_return(status: 200, body: dummy_token_response.to_json, headers: res_headers)
end

def dummy_token_response
{
:access_token => @access_token,
:token_type => 'bearer',
:refresh_token => @refresh_token,
:expires_in => 3600,
:scope => 'user_profile'
access_token: @access_token,
token_type: 'bearer',
refresh_token: @refresh_token,
expires_in: 3600,
scope: 'user_profile'
}
end

Expand All @@ -61,55 +61,55 @@ def add_mock_user_info
url = 'https://zoom.us/v2/users/me'
headers = {'Authorization' => "Bearer #{@access_token}"}
res_headers = {'Content-Type' => 'application/json'}
stub_request(:get, url).with(:headers => headers).to_return(:status => 200, :body => dummy_user_info_response.to_json, :headers => res_headers)
stub_request(:get, url).with(headers: headers).to_return(status: 200, body: dummy_user_info_response.to_json, headers: res_headers)
end

def add_mock_user_info_then_fail_because_of_missing_scope
WebMock.enable!
url = 'https://zoom.us/v2/users/me'
response = {:code => 124, :message => 'Invalid access token.'}
response = {code: 124, message: 'Invalid access token.'}
headers = {'Authorization' => "Bearer #{@access_token}"}
res_headers = {'Content-Type' => 'application/json'}
stub_request(:get, url).with(:headers => headers).to_return(:status => 400, :body => response.to_json, :headers => res_headers)
stub_request(:get, url).with(headers: headers).to_return(status: 400, body: response.to_json, headers: res_headers)
end

def add_mock_user_info_then_fail_because_of_unknown
WebMock.enable!
url = 'https://zoom.us/v2/users/me'
response = {:code => 999, :message => 'Unknown Error'}
response = {code: 999, message: 'Unknown Error'}
headers = {'Authorization' => "Bearer #{@access_token}"}
res_headers = {'Content-Type' => 'application/json'}
stub_request(:get, url).with(:headers => headers).to_return(:status => 500, :body => response.to_json, :headers => res_headers)
stub_request(:get, url).with(headers: headers).to_return(status: 500, body: response.to_json, headers: res_headers)
end

def dummy_user_info_response
{
:id => 'KdYKjnimT4KPd8FFgQt9FQ',
:first_name => 'Jane',
:last_name => 'Dev',
:email => 'jane.dev@email.com',
:type => 2,
:role_name => 'Owner',
:pmi => 1_234_567_890,
:use_pmi => false,
:vanity_url => 'https://janedevinc.zoom.us/my/janedev',
:personal_meeting_url => 'https://janedevinc.zoom.us/j/1234567890',
:timezone => 'America/Denver',
:verified => 1,
:dept => '',
:created_at => '2019-04-05T15:24:32Z',
:last_login_time => '2019-12-16T18:02:48Z',
:last_client_version => '4.6.12611.1124(mac)',
:pic_url => 'https://janedev.zoom.us/p/KdYKjnimFR5Td8KKdQt9FQ/19f6430f-ca72-4154-8998-ede6be4542c7-837',
:host_key => '533895',
:jid => 'kdykjnimt4kpd8kkdqt9fq@xmpp.zoom.us',
:group_ids => [],
:im_group_ids => ['3NXCD9VFTCOUH8LD-QciGw'],
:account_id => 'gVcjZnYYRLDbb_MfgHuaxg',
:language => 'en-US',
:phone_country => 'US',
:phone_number => '+1 1234567891',
:status => 'active'
id: 'KdYKjnimT4KPd8FFgQt9FQ',
first_name: 'Jane',
last_name: 'Dev',
email: 'jane.dev@email.com',
type: 2,
role_name: 'Owner',
pmi: 1_234_567_890,
use_pmi: false,
vanity_url: 'https://janedevinc.zoom.us/my/janedev',
personal_meeting_url: 'https://janedevinc.zoom.us/j/1234567890',
timezone: 'America/Denver',
verified: 1,
dept: '',
created_at: '2019-04-05T15:24:32Z',
last_login_time: '2019-12-16T18:02:48Z',
last_client_version: '4.6.12611.1124(mac)',
pic_url: 'https://janedev.zoom.us/p/KdYKjnimFR5Td8KKdQt9FQ/19f6430f-ca72-4154-8998-ede6be4542c7-837',
host_key: '533895',
jid: 'kdykjnimt4kpd8kkdqt9fq@xmpp.zoom.us',
group_ids: [],
im_group_ids: ['3NXCD9VFTCOUH8LD-QciGw'],
account_id: 'gVcjZnYYRLDbb_MfgHuaxg',
language: 'en-US',
phone_country: 'US',
phone_number: '+1 1234567891',
status: 'active'
}
end
end

0 comments on commit 674eee2

Please sign in to comment.