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

Commit 00cf74e

Browse files
committed
Support paths with getToken
Closes #18
1 parent 52e4a03 commit 00cf74e

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ You can override the request mechanism if you need a custom implementation by se
7474

7575
```javascript
7676
var express = require('express')
77-
var app = express()
77+
var app = express()
7878

7979
app.get('/auth/github', function (req, res) {
8080
var uri = githubAuth.code.getUri()

client-oauth2.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -480,17 +480,17 @@ TokenFlow.prototype.getUri = function (options) {
480480
TokenFlow.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

Comments
 (0)