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

Support OAuth flow for Connect accounts #555

Merged
merged 10 commits into from
Jan 25, 2019
5 changes: 4 additions & 1 deletion lib/StripeResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function StripeResource(stripe, urlData) {
this._stripe = stripe;
this._urlData = urlData || {};

this.basePath = utils.makeURLInterpolator(stripe.getApiField('basePath'));
this.basePath = utils.makeURLInterpolator(this.basePath || stripe.getApiField('basePath'));
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved
this.resourcePath = this.path;
this.path = utils.makeURLInterpolator(this.path);

Expand All @@ -40,6 +40,9 @@ StripeResource.prototype = {

path: '',

// Methods that don't use the API's default '/v1' path can override it with this setting.
basePath: null,
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved

initialize: function() {},

// Function to override the default data processor. This allows full control
Expand Down
15 changes: 15 additions & 0 deletions lib/resources/Oauth/Token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

var StripeResource = require('../../StripeResource');
var stripeMethod = StripeResource.method;

module.exports = StripeResource.extend({
path: 'oauth',
basePath: '/',

create: stripeMethod({
method: 'POST',
path: 'token',
host: 'connect.stripe.com',
}),
});
3 changes: 3 additions & 0 deletions lib/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ var resources = {
Disputes: require('./resources/Issuing/Disputes'),
Transactions: require('./resources/Issuing/Transactions'),
}),
Oauth: resourceNamespace('oauth', {
Token: require('./resources/Oauth/Token'),
}),
Radar: resourceNamespace('radar', {
ValueLists: require('./resources/Radar/ValueLists'),
ValueListItems: require('./resources/Radar/ValueListItems'),
Expand Down
28 changes: 28 additions & 0 deletions test/resources/Oauth/Token.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

var stripe = require('../../../testUtils').getSpyableStripe();
var expect = require('chai').expect;

describe('Oauth', function() {
describe('Token Resource', function() {
describe('create', function() {
it('Sends the correct request', function() {
stripe.oauth.token.create({
code: '123abc',
grant_type: 'authorization_code'
});

expect(stripe.LAST_REQUEST).to.deep.equal({
method: 'POST',
host: 'connect.stripe.com',
url: '/oauth/token',
headers: {},
data: {
code: '123abc',
grant_type: 'authorization_code'
},
});
});
});
});
});