Skip to content
This repository was archived by the owner on Jan 20, 2024. It is now read-only.

Commit 08927fe

Browse files
authored
Update dependencies for ES2015 (#45)
1 parent 2e36a95 commit 08927fe

File tree

6 files changed

+61
-64
lines changed

6 files changed

+61
-64
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@ notifications:
77
on_failure: change
88

99
node_js:
10-
- "0.10"
11-
- "0.12"
1210
- "4"
1311
- "stable"

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ githubAuth.jwt.getToken('eyJhbGciOiJFUzI1NiJ9.eyJpc3Mi[...omitted for brevity...
180180
})
181181
```
182182

183+
## Dependencies
184+
185+
Requires an ES5 environment with global `Promise` and `Object.assign`.
186+
183187
## License
184188

185189
Apache 2.0

package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"test-node": "PORT=7357 mocha -R spec --bail --require test/support/globals.js",
2222
"test": "npm run lint && npm run test-server-open && npm run test-node && npm run test-browser; npm run test-server-close"
2323
},
24+
"engines": {
25+
"node": ">=4.2.0"
26+
},
2427
"repository": {
2528
"type": "git",
2629
"url": "git://github.com/mulesoft/js-client-oauth2.git"
@@ -38,11 +41,10 @@
3841
"homepage": "https://github.com/mulesoft/js-client-oauth2",
3942
"devDependencies": {
4043
"body-parser": "^1.15.2",
41-
"browserify": "^13.1.0",
44+
"browserify": "^14.1.0",
4245
"chai": "^3.2.0",
4346
"cors": "^2.8.1",
44-
"envify": "^3.4.1",
45-
"es6-promise": "^3.1.2",
47+
"envify": "^4.0.0",
4648
"express": "^4.14.0",
4749
"is-travis": "^1.0.0",
4850
"karma": "^1.3.0",
@@ -55,13 +57,13 @@
5557
"karma-mocha": "^1.1.1",
5658
"karma-phantomjs-launcher": "^1.0.0",
5759
"mocha": "^3.0.2",
60+
"object-assign": "^4.1.1",
5861
"phantomjs": "^2.1.3",
5962
"phantomjs-prebuilt": "^2.1.4",
60-
"standard": "^8.1.0",
63+
"standard": "^9.0.2",
6164
"watchify": "^3.7.0"
6265
},
6366
"dependencies": {
64-
"popsicle": "^8.2.0",
65-
"xtend": "^4.0.1"
67+
"popsicle": "^9.1.0"
6668
}
6769
}

src/client-oauth2.js

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var extend = require('xtend')
21
var Querystring = require('querystring')
32
var Url = require('url')
43
var defaultRequest = require('./request')
@@ -155,16 +154,13 @@ function createUri (options, tokenType) {
155154
// Check the required parameters are set.
156155
expects(options, 'clientId', 'authorizationUri')
157156

158-
return options.authorizationUri + '?' + Querystring.stringify(extend(
159-
options.query,
160-
{
161-
client_id: options.clientId,
162-
redirect_uri: options.redirectUri,
163-
scope: sanitizeScope(options.scopes),
164-
response_type: tokenType,
165-
state: options.state
166-
}
167-
))
157+
return options.authorizationUri + '?' + Querystring.stringify(Object.assign({}, options.query, {
158+
client_id: options.clientId,
159+
redirect_uri: options.redirectUri,
160+
scope: sanitizeScope(options.scopes),
161+
response_type: tokenType,
162+
state: options.state
163+
}))
168164
}
169165

170166
/**
@@ -195,9 +191,9 @@ function requestOptions (requestOptions, options) {
195191
return {
196192
url: requestOptions.url,
197193
method: requestOptions.method,
198-
body: extend(requestOptions.body, options.body),
199-
query: extend(requestOptions.query, options.query),
200-
headers: extend(requestOptions.headers, options.headers)
194+
body: Object.assign({}, requestOptions.body, options.body),
195+
query: Object.assign({}, requestOptions.query, options.query),
196+
headers: Object.assign({}, requestOptions.headers, options.headers)
201197
}
202198
}
203199

@@ -234,7 +230,8 @@ ClientOAuth2.Token = ClientOAuth2Token
234230
* @return {Object}
235231
*/
236232
ClientOAuth2.prototype.createToken = function (access, refresh, type, data) {
237-
var options = extend(
233+
var options = Object.assign(
234+
{},
238235
data,
239236
typeof access === 'string' ? { access_token: access } : access,
240237
typeof refresh === 'string' ? { refresh_token: refresh } : refresh,
@@ -352,12 +349,12 @@ ClientOAuth2Token.prototype.sign = function (requestObject) {
352349
/**
353350
* Refresh a user access token with the supplied token.
354351
*
352+
* @param {Object} opts
355353
* @return {Promise}
356354
*/
357-
ClientOAuth2Token.prototype.refresh = function (options) {
355+
ClientOAuth2Token.prototype.refresh = function (opts) {
358356
var self = this
359-
360-
options = extend(this.client.options, options)
357+
var options = Object.assign({}, this.client.options, opts)
361358

362359
if (!this.refreshToken) {
363360
return Promise.reject(new Error('No refresh token'))
@@ -366,7 +363,7 @@ ClientOAuth2Token.prototype.refresh = function (options) {
366363
return this.client._request(requestOptions({
367364
url: options.accessTokenUri,
368365
method: 'POST',
369-
headers: extend(DEFAULT_HEADERS, {
366+
headers: Object.assign({}, DEFAULT_HEADERS, {
370367
Authorization: auth(options.clientId, options.clientSecret)
371368
}),
372369
body: {
@@ -375,7 +372,7 @@ ClientOAuth2Token.prototype.refresh = function (options) {
375372
}
376373
}, options))
377374
.then(function (data) {
378-
return self.client.createToken(extend(self.data, data))
375+
return self.client.createToken(Object.assign({}, self.data, data))
379376
})
380377
}
381378

@@ -404,17 +401,17 @@ function OwnerFlow (client) {
404401
*
405402
* @param {string} username
406403
* @param {string} password
404+
* @param {Object} [opts]
407405
* @return {Promise}
408406
*/
409-
OwnerFlow.prototype.getToken = function (username, password, options) {
407+
OwnerFlow.prototype.getToken = function (username, password, opts) {
410408
var self = this
411-
412-
options = extend(this.client.options, options)
409+
var options = Object.assign({}, this.client.options, opts)
413410

414411
return this.client._request(requestOptions({
415412
url: options.accessTokenUri,
416413
method: 'POST',
417-
headers: extend(DEFAULT_HEADERS, {
414+
headers: Object.assign({}, DEFAULT_HEADERS, {
418415
Authorization: auth(options.clientId, options.clientSecret)
419416
}),
420417
body: {
@@ -443,11 +440,11 @@ function TokenFlow (client) {
443440
/**
444441
* Get the uri to redirect the user to for implicit authentication.
445442
*
446-
* @param {Object} options
443+
* @param {Object} [opts]
447444
* @return {string}
448445
*/
449-
TokenFlow.prototype.getUri = function (options) {
450-
options = extend(this.client.options, options)
446+
TokenFlow.prototype.getUri = function (opts) {
447+
var options = Object.assign({}, this.client.options, opts)
451448

452449
return createUri(options, 'token')
453450
}
@@ -456,12 +453,11 @@ TokenFlow.prototype.getUri = function (options) {
456453
* Get the user access token from the uri.
457454
*
458455
* @param {string|Object} uri
459-
* @param {Object} [options]
456+
* @param {Object} [opts]
460457
* @return {Promise}
461458
*/
462-
TokenFlow.prototype.getToken = function (uri, options) {
463-
options = extend(this.client.options, options)
464-
459+
TokenFlow.prototype.getToken = function (uri, opts) {
460+
var options = Object.assign({}, this.client.options, opts)
465461
var url = typeof uri === 'object' ? uri : Url.parse(uri, true)
466462
var expectedUrl = Url.parse(options.redirectUri)
467463

@@ -480,7 +476,8 @@ TokenFlow.prototype.getToken = function (uri, options) {
480476
// Extract data from both the fragment and query string. The fragment is most
481477
// important, but the query string is also used because some OAuth 2.0
482478
// implementations (Instagram) have a bug where state is passed via query.
483-
var data = extend(
479+
var data = Object.assign(
480+
{},
484481
typeof url.query === 'string' ? Querystring.parse(url.query) : (url.query || {}),
485482
typeof url.hash === 'string' ? Querystring.parse(url.hash.substr(1)) : (url.hash || {})
486483
)
@@ -515,20 +512,19 @@ function CredentialsFlow (client) {
515512
/**
516513
* Request an access token using the client credentials.
517514
*
518-
* @param {Object} [options]
515+
* @param {Object} [opts]
519516
* @return {Promise}
520517
*/
521-
CredentialsFlow.prototype.getToken = function (options) {
518+
CredentialsFlow.prototype.getToken = function (opts) {
522519
var self = this
523-
524-
options = extend(this.client.options, options)
520+
var options = Object.assign({}, this.client.options, opts)
525521

526522
expects(options, 'clientId', 'clientSecret', 'accessTokenUri')
527523

528524
return this.client._request(requestOptions({
529525
url: options.accessTokenUri,
530526
method: 'POST',
531-
headers: extend(DEFAULT_HEADERS, {
527+
headers: Object.assign({}, DEFAULT_HEADERS, {
532528
Authorization: auth(options.clientId, options.clientSecret)
533529
}),
534530
body: {
@@ -555,10 +551,11 @@ function CodeFlow (client) {
555551
/**
556552
* Generate the uri for doing the first redirect.
557553
*
554+
* @param {Object} [opts]
558555
* @return {string}
559556
*/
560-
CodeFlow.prototype.getUri = function (options) {
561-
options = extend(this.client.options, options)
557+
CodeFlow.prototype.getUri = function (opts) {
558+
var options = Object.assign({}, this.client.options, opts)
562559

563560
return createUri(options, 'code')
564561
}
@@ -568,13 +565,12 @@ CodeFlow.prototype.getUri = function (options) {
568565
* the user access token.
569566
*
570567
* @param {string|Object} uri
571-
* @param {Object} [options]
568+
* @param {Object} [opts]
572569
* @return {Promise}
573570
*/
574-
CodeFlow.prototype.getToken = function (uri, options) {
571+
CodeFlow.prototype.getToken = function (uri, opts) {
575572
var self = this
576-
577-
options = extend(this.client.options, options)
573+
var options = Object.assign({}, this.client.options, opts)
578574

579575
expects(options, 'clientId', 'accessTokenUri')
580576

@@ -610,7 +606,7 @@ CodeFlow.prototype.getToken = function (uri, options) {
610606
return Promise.reject(new TypeError('Missing code, unable to request token'))
611607
}
612608

613-
var headers = extend(DEFAULT_HEADERS)
609+
var headers = Object.assign({}, DEFAULT_HEADERS)
614610
var body = { code: data.code, grant_type: 'authorization_code', redirect_uri: options.redirectUri }
615611

616612
// `client_id`: REQUIRED, if the client is not authenticating with the
@@ -648,18 +644,16 @@ function JwtBearerFlow (client) {
648644
* Request an access token using a JWT token.
649645
*
650646
* @param {string} token A JWT token.
651-
* @param {Object} [options]
647+
* @param {Object} [opts]
652648
* @return {Promise}
653649
*/
654-
JwtBearerFlow.prototype.getToken = function (token, options) {
650+
JwtBearerFlow.prototype.getToken = function (token, opts) {
655651
var self = this
656-
657-
options = extend(this.client.options, options)
652+
var options = Object.assign({}, this.client.options, opts)
653+
var headers = Object.assign({}, DEFAULT_HEADERS)
658654

659655
expects(options, 'accessTokenUri')
660656

661-
var headers = extend(DEFAULT_HEADERS)
662-
663657
// Authentication of the client is optional, as described in
664658
// Section 3.2.1 of OAuth 2.0 [RFC6749]
665659
if (options.clientId) {

test/code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('code', function () {
4747
expect(err.body.error).to.equal('invalid_request')
4848
})
4949
.then(function () {
50-
expect(errored).to.be.true
50+
expect(errored).to.equal(true)
5151
})
5252
})
5353

test/support/globals.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
require('es6-promise').polyfill()
1+
Object.assign = Object.assign || require('object-assign')
2+
global.Promise = global.Promise || require('es6-promise').Promise
23

3-
if (!global.btoa) {
4-
global.btoa = function (str) {
5-
return new Buffer(str).toString('base64')
6-
}
4+
global.btoa = global.btoa || function (str) {
5+
return new Buffer(str).toString('base64')
76
}

0 commit comments

Comments
 (0)