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 #21 from koshilife/#18-support-x-www-form-urlencoded
Browse files Browse the repository at this point in the history
release 1.1.0 - change to use x-www-form-urlencoded
  • Loading branch information
koshilife authored Aug 24, 2021
2 parents cb249bf + b3bbbcc commit e2320ba
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
# CHANGELOG

## 1.1.0

- change to use x-www-form-urlencoded in the request of getting tokens.(#18)

## 1.0.0

- allowed for omniauth 2.0 series.

## 0.4.0

- This release supported for omniauth 1.0 series.
- change to use x-www-form-urlencoded in the request of getting tokens.(#18)

## 0.3.0

- be specified dependency for omniauth 1.9.
Expand Down
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 = '1.0.0'
VERSION = '1.1.0'
end
end
19 changes: 5 additions & 14 deletions lib/omniauth/strategies/zoom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ 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)
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
Expand All @@ -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
Expand All @@ -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',
Expand Down

0 comments on commit e2320ba

Please sign in to comment.