From 294b20394f7a1dd9ac66af53aebe60dc026a1181 Mon Sep 17 00:00:00 2001 From: Kenji Koshikawa Date: Mon, 23 Aug 2021 09:36:19 +0900 Subject: [PATCH 1/3] refs #18 change to use x-www-form-urlencoded in request of getting tokens. --- lib/omniauth/strategies/zoom.rb | 19 +++++-------------- test/test_helper.rb | 4 ++-- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/lib/omniauth/strategies/zoom.rb b/lib/omniauth/strategies/zoom.rb index 750d8c1..8ca6518 100644 --- a/lib/omniauth/strategies/zoom.rb +++ b/lib/omniauth/strategies/zoom.rb @@ -14,20 +14,11 @@ class Zoom < OmniAuth::Strategies::OAuth2 uid { raw_info['id'] } extra { {raw_info: raw_info} } - protected - - def build_access_token - params = { - 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}"}} - - res = client.request(:post, path, opts) - ::OAuth2::AccessToken.from_hash(client, res.parsed) + def token_params + params = super + params[:headers] ||= {} + params[:headers][:Authorization] = format('Basic %s', Base64.strict_encode64("#{client.id}:#{client.secret}")) + params end private diff --git a/test/test_helper.rb b/test/test_helper.rb index afedb86..40ce931 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -39,9 +39,9 @@ def strategy def add_mock_exchange_token WebMock.enable! - url = "https://zoom.us/oauth/token?code=#{@authorization_code}&grant_type=authorization_code&redirect_uri=http://example.org/auth/zoom/callback" + url = 'https://zoom.us/oauth/token' secret = Base64.strict_encode64("#{@client_id}:#{@client_secret}") - headers = {'Authorization' => "Basic #{secret}"} + headers = {'Authorization' => "Basic #{secret}", 'Content-Type' => 'application/x-www-form-urlencoded'} 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) end From 4abcf6340fb1f4fce1fa2bc4d41a9c37f2de80e4 Mon Sep 17 00:00:00 2001 From: Kenji Koshikawa Date: Mon, 23 Aug 2021 09:40:45 +0900 Subject: [PATCH 2/3] fix rubocop warnings. --- test/test_helper.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 40ce931..036faa1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -43,7 +43,8 @@ def add_mock_exchange_token secret = Base64.strict_encode64("#{@client_id}:#{@client_secret}") headers = {'Authorization' => "Basic #{secret}", 'Content-Type' => 'application/x-www-form-urlencoded'} 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 @@ -61,7 +62,8 @@ 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 @@ -82,7 +84,7 @@ def add_mock_user_info_then_fail_because_of_unknown stub_request(:get, url).with(headers: headers).to_return(status: 500, body: response.to_json, headers: res_headers) end - def dummy_user_info_response + def dummy_user_info_response # rubocop:disable Metrics/MethodLength { id: 'KdYKjnimT4KPd8FFgQt9FQ', first_name: 'Jane', From d9681dca068397c8ecc6dcaee1d6c23f0303b95f Mon Sep 17 00:00:00 2001 From: Kenji Koshikawa Date: Tue, 24 Aug 2021 09:48:45 +0900 Subject: [PATCH 3/3] set version to 0.4.0 --- CHANGELOG.md | 4 ++++ lib/omniauth-zoom/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35dd127..a392441 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.4.0 + +- change to use x-www-form-urlencoded in the request of getting tokens.(#18) + ## 0.3.0 - be specified dependency for omniauth 1.9. diff --git a/lib/omniauth-zoom/version.rb b/lib/omniauth-zoom/version.rb index 1399b15..3093e58 100644 --- a/lib/omniauth-zoom/version.rb +++ b/lib/omniauth-zoom/version.rb @@ -2,6 +2,6 @@ module OmniAuth module Zoom - VERSION = '0.3.1' + VERSION = '0.4.0' end end