Merge pull request #562 from ymendel/handle_invalid_client_oauth_error

handle invalid-client oauth error
This commit is contained in:
Brandur 2017-07-27 08:53:35 -07:00 committed by GitHub
commit 713d7f9fa8
3 changed files with 25 additions and 0 deletions

View File

@ -114,6 +114,12 @@ module Stripe
end
end
# InvalidClientError is raised when the client doesn't belong to you, or
# the API key mode (live or test) doesn't match the client mode. Or the
# stripe_user_id doesn't exist or isn't connected to your application.
class InvalidClientError < OAuthError
end
# InvalidGrantError is raised when a specified code doesn't exist, is
# expired, has been used, or doesn't belong to you; a refresh token doesn't
# exist, or doesn't belong to you; or if an API key's mode (live or test)

View File

@ -312,6 +312,7 @@ module Stripe
}]
case error_code
when 'invalid_client' then OAuth::InvalidClientError.new(*args)
when 'invalid_grant' then OAuth::InvalidGrantError.new(*args)
when 'invalid_request' then OAuth::InvalidRequestError.new(*args)
when 'invalid_scope' then OAuth::InvalidScopeError.new(*args)

View File

@ -368,6 +368,24 @@ module Stripe
assert_equal('invalid_grant', e.code)
assert_equal('This authorization code has already been used. All tokens issued with this code have been revoked.', e.message)
end
should "raise OAuth::InvalidClientError when error is a string with value 'invalid_client'" do
stub_request(:post, "#{Stripe.connect_base}/oauth/deauthorize").
to_return(body: JSON.generate({
error: "invalid_client",
error_description: "This application is not connected to stripe account acct_19tLK7DSlTMT26Mk, or that account does not exist.",
}), status: 401)
client = StripeClient.new
opts = {api_base: Stripe.connect_base}
e = assert_raises Stripe::OAuth::InvalidClientError do
client.execute_request(:post, '/oauth/deauthorize', opts)
end
assert_equal(401, e.http_status)
assert_equal('invalid_client', e.code)
assert_equal('This application is not connected to stripe account acct_19tLK7DSlTMT26Mk, or that account does not exist.', e.message)
end
end
context "idempotency keys" do