Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix auth token revocation (broken since 0.6.3) #157

Merged
merged 1 commit into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/googleauth/user_refresh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def revoke!(options = {})
c = options[:connection] || Faraday.default_connection

retry_with_error do
resp = c.get(REVOKE_TOKEN_URI, token: refresh_token || access_token)
resp = c.post(REVOKE_TOKEN_URI, token: refresh_token || access_token)
case resp.status
when 200
self.access_token = nil
Expand Down
10 changes: 5 additions & 5 deletions spec/googleauth/user_authorizer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,17 +299,17 @@

before(:example) do
token_store.store('user1', token_json)
stub_request(
:get, 'https://oauth2.googleapis.com/revoke?token=refreshtoken'
)
stub_request(:post, 'https://oauth2.googleapis.com/revoke')
.with(body: hash_including('token' => 'refreshtoken'))
.to_return(status: 200)
end

it 'should revoke the grant' do
authorizer.revoke_authorization('user1')
expect(a_request(
:get, 'https://oauth2.googleapis.com/revoke?token=refreshtoken'
))
:post, 'https://oauth2.googleapis.com/revoke'
).with(body: hash_including('token' => 'refreshtoken'))
)
.to have_been_made
end

Expand Down
16 changes: 8 additions & 8 deletions spec/googleauth/user_refresh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ def cred_json_text(missing = nil)

describe 'when revoking a refresh token' do
let(:stub) do
stub_request(:get, 'https://oauth2.googleapis.com/revoke' \
'?token=refreshtoken')
stub_request(:post, 'https://oauth2.googleapis.com/revoke')
.with(body: hash_including('token' => 'refreshtoken'))
.to_return(status: 200,
headers: { 'Content-Type' => 'application/json' })
end
Expand All @@ -262,8 +262,8 @@ def cred_json_text(missing = nil)

describe 'when revoking an access token' do
let(:stub) do
stub_request(:get, 'https://oauth2.googleapis.com/revoke' \
'?token=accesstoken')
stub_request(:post, 'https://oauth2.googleapis.com/revoke')
.with(body: hash_including('token' => 'accesstoken'))
.to_return(status: 200,
headers: { 'Content-Type' => 'application/json' })
end
Expand All @@ -280,8 +280,8 @@ def cred_json_text(missing = nil)

describe 'when revoking an invalid token' do
let(:stub) do
stub_request(:get, 'https://oauth2.googleapis.com/revoke' \
'?token=refreshtoken')
stub_request(:post, 'https://oauth2.googleapis.com/revoke')
.with(body: hash_including('token' => 'refreshtoken'))
.to_return(status: 400,
headers: { 'Content-Type' => 'application/json' })
end
Expand All @@ -296,14 +296,14 @@ def cred_json_text(missing = nil)

describe 'when errors occurred with request' do
it 'should fail with Signet::AuthorizationError if request times out' do
allow_any_instance_of(Faraday::Connection).to receive(:get)
allow_any_instance_of(Faraday::Connection).to receive(:post)
.and_raise(Faraday::TimeoutError)
expect { @client.revoke! }
.to raise_error Signet::AuthorizationError
end

it 'should fail with Signet::AuthorizationError if request fails' do
allow_any_instance_of(Faraday::Connection).to receive(:get)
allow_any_instance_of(Faraday::Connection).to receive(:post)
.and_raise(Faraday::ConnectionFailed, nil)
expect { @client.revoke! }
.to raise_error Signet::AuthorizationError
Expand Down