Skip to content
This repository was archived by the owner on Jul 19, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ module.exports = {
throw new Error('Authorization URLs are not supported for password authentication');
}

return new URI({
protocol: 'https',
hostname: this._getUtils()._getDomain(this.apiURL),
path: AUTH_PATH
}).setQuery(query).toString();
return new URI(this.apiURL).subdomain("").path(AUTH_PATH).query(query).toString();
},

authenticateWithCredentialsForOffering: function(username, password, offeringId, callback) {
Expand Down Expand Up @@ -206,11 +202,8 @@ module.exports = {
},

_authenticate: function(requestData, callback) {
var url = new URI({
protocol: 'https',
hostname: this._getUtils()._getDomain(this.apiURL),
path: TOKEN_PATH
}).toString();

var url = new URI(this.apiURL).path(TOKEN_PATH).toString();

_.extend(requestData, {
client_id: this.clientId,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "podio-js",
"version": "1.4.0",
"version": "1.4.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't increment versions on branches. Only ever do this on master. When you do, use npm version <major|minor|patch> which will also create the corresponding tag to keep Github releases in sync with npm releases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did use npm version. I'll remember to run it on master from now on, though. Thanks

"description": "Podio Platform JavaScript SDK for NodeJS and the browser",
"main": "lib/index",
"scripts": {
Expand Down
28 changes: 9 additions & 19 deletions test/auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,39 +131,33 @@ describe('auth', function() {

it('should return the correct authorization URL for the client auth', function() {
var redirectURL = 'https://www.myapp.com/oauth';
var utils = {
_getDomain: sinon.stub().returns('podio.com')
};
var host = {
_getUtils: sinon.stub().returns(utils),
apiURL: 'https://api.podio.com',
authType: 'client',
clientId: 123
};

var expectedURL = 'https://podio.com/oauth/authorize?client_id=123&redirect_uri=https%3A%2F%2Fwww.myapp.com%2Foauth&response_type=token';

expect(auth.getAuthorizationURL.call(host, redirectURL)).toEqual(expectedURL);
expect(utils._getDomain.calledOnce).toBe(true);

expect(auth.getAuthorizationURL.call(host, redirectURL)).toBe(expectedURL);
});

it('should return the correct authorization URL for the server auth', function() {
var redirectURL = 'https://www.myapp.com/oauth';
var utils = {
_getDomain: sinon.stub().returns('podio.com')
};

var host = {
_getUtils: sinon.stub().returns(utils),
apiURL: 'https://podio.com',
authType: 'server',
clientId: 123
};
var expectedURL = 'https://podio.com/oauth/authorize?client_id=123&redirect_uri=https%3A%2F%2Fwww.myapp.com%2Foauth&response_type=code';

expect(auth.getAuthorizationURL.call(host, redirectURL)).toEqual(expectedURL);
expect(auth.getAuthorizationURL.call(host, redirectURL)).toBe(expectedURL);
});

it('should throw an error when retrieving an auth URL for password auth', function() {
var redirectURL = 'https://www.myapp.com/oauth';
var host = {
utils: { _getDomain: sinon.stub().returns('podio.com') },
authType: 'password',
clientId: 123
};
Expand Down Expand Up @@ -437,11 +431,8 @@ describe('auth', function() {
describe('_authenticate', function() {

it('should construct the request data and url correctly', function() {
var utils = {
_getDomain: sinon.stub().returns('podio.com')
};
var host = {
_getUtils: sinon.stub().returns(utils),
apiURL: 'http://sub.podio.com',
clientId: 123,
clientSecret: 'secret',
_authRequest: sinon.stub()
Expand All @@ -456,10 +447,9 @@ describe('auth', function() {
auth._authenticate.call(host, requestData);

expect(host._authRequest.calledOnce).toBe(true);
expect(host._authRequest.getCall(0).args[0]).toEqual('https://podio.com/oauth/token');
expect(host._authRequest.getCall(0).args[0]).toEqual('http://sub.podio.com/oauth/token');
expect(host._authRequest.getCall(0).args[1]).toEqual(expectedRequestData);
});

});

describe('_onAuthResponse', function() {
Expand Down