1- var extend = require ( 'xtend' )
21var Querystring = require ( 'querystring' )
32var Url = require ( 'url' )
43var 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 */
236232ClientOAuth2 . 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 ) {
0 commit comments