@@ -480,17 +480,17 @@ TokenFlow.prototype.getUri = function (options) {
480480TokenFlow . prototype . getToken = function ( uri , state , options ) {
481481 options = extend ( this . client . options , options )
482482
483- // Make sure the uri matches our expected redirect uri.
484- if ( uri . substr ( 0 , options . redirectUri . length ) !== options . redirectUri ) {
485- return Promise . reject ( new Error ( 'Should match redirect uri: ' + uri ) )
486- }
487-
488483 var url = parseUrl ( uri )
484+ var expectedUrl = parseUrl ( options . redirectUri )
485+
486+ if ( url . pathname !== expectedUrl . pathname ) {
487+ return Promise . reject ( new TypeError ( 'Should match redirect uri: ' + uri ) )
488+ }
489489
490490 // If no query string or fragment exists, we won't be able to parse
491491 // any useful information from the uri.
492492 if ( ! url . hash && ! url . search ) {
493- return Promise . reject ( new Error ( 'Unable to process uri: ' + uri ) )
493+ return Promise . reject ( new TypeError ( 'Unable to process uri: ' + uri ) )
494494 }
495495
496496 // Extract data from both the fragment and query string. The fragment is most
@@ -510,7 +510,7 @@ TokenFlow.prototype.getToken = function (uri, state, options) {
510510
511511 // Check whether the state matches.
512512 if ( state != null && data . state !== state ) {
513- return Promise . reject ( new Error ( 'Invalid state: ' + data . state ) )
513+ return Promise . reject ( new TypeError ( 'Invalid state: ' + data . state ) )
514514 }
515515
516516 // Initalize a new token and return.
@@ -605,15 +605,15 @@ CodeFlow.prototype.getToken = function (uri, state, options) {
605605 'accessTokenUri'
606606 ] )
607607
608- // Make sure the uri matches our expected redirect uri.
609- if ( uri . substr ( 0 , options . redirectUri . length ) !== options . redirectUri ) {
610- return Promise . reject ( new Error ( 'Should match redirect uri: ' + uri ) )
611- }
612-
613608 var url = parseUrl ( uri )
609+ var expectedUrl = parseUrl ( options . redirectUri )
610+
611+ if ( url . pathname !== expectedUrl . pathname ) {
612+ return Promise . reject ( new TypeError ( 'Should match redirect uri: ' + uri ) )
613+ }
614614
615615 if ( ! url . search ) {
616- return Promise . reject ( new Error ( 'Unable to process uri: ' + uri ) )
616+ return Promise . reject ( new TypeError ( 'Unable to process uri: ' + uri ) )
617617 }
618618
619619 var data = parseQuery ( url . query )
@@ -624,12 +624,12 @@ CodeFlow.prototype.getToken = function (uri, state, options) {
624624 }
625625
626626 if ( state && data . state !== state ) {
627- return Promise . reject ( new Error ( 'Invalid state:' + data . state ) )
627+ return Promise . reject ( new TypeError ( 'Invalid state:' + data . state ) )
628628 }
629629
630630 // Check whether the response code is set.
631631 if ( ! data . code ) {
632- return Promise . reject ( new Error ( 'Missing code, unable to request token' ) )
632+ return Promise . reject ( new TypeError ( 'Missing code, unable to request token' ) )
633633 }
634634
635635 return this . client . _request ( requestOptions ( {
0 commit comments