Skip to content

Commit

Permalink
Generate OAuth authorize URLs for express accounts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
brandur committed Dec 31, 2018
1 parent 6f81c90 commit 403be3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/stripe/oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ def self.get_client_id(params = {})
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 = {})
Expand Down
9 changes: 9 additions & 0 deletions test/stripe/oauth_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ class OAuthTest < Test::Unit::TestCase
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
Expand Down

0 comments on commit 403be3b

Please sign in to comment.