Skip to content

Commit

Permalink
Override API key with client_secret in OAuth.token (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe authored Jan 6, 2020
1 parent e23ae43 commit cddd3db
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/stripe/oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def self.authorize_url(params = {}, opts = {})

def self.token(params = {}, opts = {})
opts = Util.normalize_opts(opts)
opts[:api_key] = params[:client_secret] if params[:client_secret]
resp, opts = OAuthOperations.request(
:post, "/oauth/token", params, opts
)
Expand Down
16 changes: 16 additions & 0 deletions test/stripe/oauth_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ class OAuthTest < Test::Unit::TestCase
code: "this_is_an_authorization_code")
assert_equal("sk_access_token", resp.access_token)
end

should "override the API key when client_secret is passed" do
stub_request(:post, "#{Stripe.connect_base}/oauth/token")
.with(body: {
"client_secret" => "client_secret_override",
"grant_type" => "authorization_code",
"code" => "this_is_an_authorization_code",
})
.with(headers: { "Authorization": "Bearer client_secret_override" })
.to_return(body: JSON.generate(access_token: "another_access_token"))

resp = OAuth.token(client_secret: "client_secret_override",
grant_type: "authorization_code",
code: "this_is_an_authorization_code")
assert_equal("another_access_token", resp.access_token)
end
end

context ".deauthorize" do
Expand Down

0 comments on commit cddd3db

Please sign in to comment.