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

Commit b98b934

Browse files
authored
Merge pull request #20 from koshilife/#18-support-x-www-form-urlencoded-for-omniauth-1.0-series
release 0.4.0 - change to use x-www-form-urlencoded
2 parents 8d09108 + d9681dc commit b98b934

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 0.4.0
4+
5+
- change to use x-www-form-urlencoded in the request of getting tokens.(#18)
6+
37
## 0.3.0
48

59
- be specified dependency for omniauth 1.9.

lib/omniauth-zoom/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module OmniAuth
44
module Zoom
5-
VERSION = '0.3.1'
5+
VERSION = '0.4.0'
66
end
77
end

lib/omniauth/strategies/zoom.rb

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,11 @@ class Zoom < OmniAuth::Strategies::OAuth2
1414
uid { raw_info['id'] }
1515
extra { {raw_info: raw_info} }
1616

17-
protected
18-
19-
def build_access_token
20-
params = {
21-
grant_type: 'authorization_code',
22-
code: request.params['code'],
23-
redirect_uri: callback_url
24-
}
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}"}}
28-
29-
res = client.request(:post, path, opts)
30-
::OAuth2::AccessToken.from_hash(client, res.parsed)
17+
def token_params
18+
params = super
19+
params[:headers] ||= {}
20+
params[:headers][:Authorization] = format('Basic %s', Base64.strict_encode64("#{client.id}:#{client.secret}"))
21+
params
3122
end
3223

3324
private

test/test_helper.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ def strategy
3939

4040
def add_mock_exchange_token
4141
WebMock.enable!
42-
url = "https://zoom.us/oauth/token?code=#{@authorization_code}&grant_type=authorization_code&redirect_uri=http://example.org/auth/zoom/callback"
42+
url = 'https://zoom.us/oauth/token'
4343
secret = Base64.strict_encode64("#{@client_id}:#{@client_secret}")
44-
headers = {'Authorization' => "Basic #{secret}"}
44+
headers = {'Authorization' => "Basic #{secret}", 'Content-Type' => 'application/x-www-form-urlencoded'}
4545
res_headers = {'Content-Type' => 'application/json'}
46-
stub_request(:post, url).with(headers: headers).to_return(status: 200, body: dummy_token_response.to_json, headers: res_headers)
46+
stub_request(:post, url).with(headers: headers).to_return(status: 200, body: dummy_token_response.to_json,
47+
headers: res_headers)
4748
end
4849

4950
def dummy_token_response
@@ -61,7 +62,8 @@ def add_mock_user_info
6162
url = 'https://zoom.us/v2/users/me'
6263
headers = {'Authorization' => "Bearer #{@access_token}"}
6364
res_headers = {'Content-Type' => 'application/json'}
64-
stub_request(:get, url).with(headers: headers).to_return(status: 200, body: dummy_user_info_response.to_json, headers: res_headers)
65+
stub_request(:get, url).with(headers: headers).to_return(status: 200, body: dummy_user_info_response.to_json,
66+
headers: res_headers)
6567
end
6668

6769
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
8284
stub_request(:get, url).with(headers: headers).to_return(status: 500, body: response.to_json, headers: res_headers)
8385
end
8486

85-
def dummy_user_info_response
87+
def dummy_user_info_response # rubocop:disable Metrics/MethodLength
8688
{
8789
id: 'KdYKjnimT4KPd8FFgQt9FQ',
8890
first_name: 'Jane',

0 commit comments

Comments
 (0)