Generate OAuth authorize URLs for express accounts

Connect with Express accounts uses a slightly different version of the
OAuth authorize URL [1] in that it's prefixed with `/express`.

Here we add a new option to `Stripe::OAuth.authorize_url` which allows
`express: true` to be passed in to generate the Express variant.

Note that the token endpoint has no equivalent so we don't need the
option there.

Fixes #717.

[1] https://stripe.com/docs/connect/oauth-reference#express-account-differences
This commit is contained in:
Brandur 2018-12-31 13:47:35 -07:00
parent 6f81c907e8
commit 403be3b106
2 changed files with 13 additions and 1 deletions

View File

@ -31,11 +31,14 @@ module Stripe
def self.authorize_url(params = {}, opts = {})
base = opts[:connect_base] || Stripe.connect_base
path = "/oauth/authorize"
path = "/express" + path if opts[:express]
params[:client_id] = get_client_id(params)
params[:response_type] ||= "code"
query = Util.encode_parameters(params)
"#{base}/oauth/authorize?#{query}"
"#{base}#{path}?#{query}"
end
def self.token(params = {}, opts = {})

View File

@ -35,6 +35,15 @@ module Stripe
assert_equal(["https://example.com/profile/test"], params["stripe_user[url]"])
assert_equal(["US"], params["stripe_user[country]"])
end
should "optionally return an express path" do
uri_str = OAuth.authorize_url({}, express: true)
uri = URI.parse(uri_str)
assert_equal("https", uri.scheme)
assert_equal("connect.stripe.com", uri.host)
assert_equal("/express/oauth/authorize", uri.path)
end
end
context ".token" do