client-oauth2
Advanced tools
Comparing version
{ | ||
"name": "client-oauth2", | ||
"version": "3.2.0", | ||
"version": "3.4.0", | ||
"description": "Straight-forward execution of OAuth 2.0 flows and authenticated API requests", | ||
"main": "src/client-oauth2.js", | ||
"typings": "index.d.ts", | ||
"files": [ | ||
"src/", | ||
"index.d.ts", | ||
"LICENSE" | ||
@@ -9,0 +11,0 @@ ], |
@@ -27,3 +27,2 @@ # Client OAuth 2.0 | ||
authorizationUri: 'https://github.com/login/oauth/authorize', | ||
authorizationGrants: ['credentials'], | ||
redirectUri: 'http://example.com/auth/github/callback', | ||
@@ -115,2 +114,4 @@ scopes: ['notifications', 'gist'] | ||
**P.S.** The `getToken` URI parameter can be an object containing `pathname` and `query` properties. | ||
### [Implicit Grant](http://tools.ietf.org/html/rfc6749#section-4.2) | ||
@@ -130,6 +131,6 @@ | ||
// Make a request to the github API for the current user. | ||
user.request({ | ||
return popsicle.request(user.sign({ | ||
method: 'get', | ||
url: 'https://api.github.com/user' | ||
}).then(function (res) { | ||
})).then(function (res) { | ||
console.log(res) //=> { body: { ... }, status: 200, headers: { ... } } | ||
@@ -144,2 +145,4 @@ }) | ||
**P.S.** The `getToken` URI parameter can be an object containing `pathname`, `query` and `hash` properties. | ||
### [Resource Owner Password Credentials Grant](http://tools.ietf.org/html/rfc6749#section-4.3) | ||
@@ -146,0 +149,0 @@ |
@@ -79,4 +79,4 @@ var extend = require('xtend') | ||
* | ||
* @param {String} string | ||
* @return {String} | ||
* @param {string} string | ||
* @return {string} | ||
*/ | ||
@@ -109,3 +109,3 @@ function btoaBuffer (string) { | ||
* @param {Object} data | ||
* @return {String} | ||
* @return {string} | ||
*/ | ||
@@ -128,3 +128,3 @@ function getAuthError (body) { | ||
* | ||
* @param {String} body | ||
* @param {string} body | ||
* @return {Object} | ||
@@ -144,3 +144,3 @@ */ | ||
* @param {Array} scopes | ||
* @return {String} | ||
* @return {string} | ||
*/ | ||
@@ -155,4 +155,4 @@ function sanitizeScope (scopes) { | ||
* @param {Object} options | ||
* @param {String} tokenType | ||
* @return {String} | ||
* @param {string} tokenType | ||
* @return {string} | ||
*/ | ||
@@ -182,5 +182,5 @@ function createUri (options, tokenType) { | ||
* | ||
* @param {String} username | ||
* @param {String} password | ||
* @return {String} | ||
* @param {string} username | ||
* @param {string} password | ||
* @return {string} | ||
*/ | ||
@@ -194,4 +194,4 @@ function auth (username, password) { | ||
* | ||
* @param {String} str | ||
* @return {String} | ||
* @param {string} str | ||
* @return {string} | ||
*/ | ||
@@ -239,5 +239,5 @@ function toString (str) { | ||
* | ||
* @param {String} access | ||
* @param {String} [refresh] | ||
* @param {String} [type] | ||
* @param {string} access | ||
* @param {string} [refresh] | ||
* @param {string} [type] | ||
* @param {Object} [data] | ||
@@ -313,3 +313,3 @@ * @return {Object} | ||
* | ||
* @param {Number|Date} duration Seconds from now to expire, or a date to expire on. | ||
* @param {number|Date} duration Seconds from now to expire, or a date to expire on. | ||
* @return {Date} | ||
@@ -396,3 +396,3 @@ */ | ||
* | ||
* @return {Boolean} | ||
* @return {boolean} | ||
*/ | ||
@@ -417,4 +417,4 @@ ClientOAuth2Token.prototype.expired = function () { | ||
* | ||
* @param {String} username | ||
* @param {String} password | ||
* @param {string} username | ||
* @param {string} password | ||
* @return {Promise} | ||
@@ -460,3 +460,3 @@ */ | ||
* @param {Object} options | ||
* @return {String} | ||
* @return {string} | ||
*/ | ||
@@ -472,4 +472,4 @@ TokenFlow.prototype.getUri = function (options) { | ||
* | ||
* @param {String} uri | ||
* @param {Object} [options] | ||
* @param {string|Object} uri | ||
* @param {Object} [options] | ||
* @return {Promise} | ||
@@ -480,7 +480,9 @@ */ | ||
var url = Url.parse(uri) | ||
var url = typeof uri === 'object' ? uri : Url.parse(uri, true) | ||
var expectedUrl = Url.parse(options.redirectUri) | ||
if (url.pathname !== expectedUrl.pathname) { | ||
return Promise.reject(new TypeError('Should match redirect uri: ' + uri)) | ||
if (typeof url.pathname === 'string' && url.pathname !== expectedUrl.pathname) { | ||
return Promise.reject( | ||
new TypeError('Redirected path should match configured path, but got: ' + url.pathname) | ||
) | ||
} | ||
@@ -490,3 +492,3 @@ | ||
// any useful information from the uri. | ||
if (!url.hash && !url.search) { | ||
if (!url.hash && !url.query) { | ||
return Promise.reject(new TypeError('Unable to process uri: ' + uri)) | ||
@@ -499,4 +501,4 @@ } | ||
var data = extend( | ||
url.query ? Querystring.parse(url.query) : {}, | ||
url.hash ? Querystring.parse(url.hash.substr(1)) : {} | ||
typeof url.query === 'string' ? Querystring.parse(url.query) : (url.query || {}), | ||
typeof url.hash === 'string' ? Querystring.parse(url.hash.substr(1)) : (url.hash || {}) | ||
) | ||
@@ -578,3 +580,3 @@ | ||
* | ||
* @return {String} | ||
* @return {string} | ||
*/ | ||
@@ -591,4 +593,4 @@ CodeFlow.prototype.getUri = function (options) { | ||
* | ||
* @param {String} uri | ||
* @param {Object} [options] | ||
* @param {string|Object} uri | ||
* @param {Object} [options] | ||
* @return {Promise} | ||
@@ -608,14 +610,16 @@ */ | ||
var url = Url.parse(uri) | ||
var url = typeof uri === 'object' ? uri : Url.parse(uri, true) | ||
var expectedUrl = Url.parse(options.redirectUri) | ||
if (url.pathname !== expectedUrl.pathname) { | ||
return Promise.reject(new TypeError('Should match redirect uri: ' + uri)) | ||
if (typeof url.pathname === 'string' && url.pathname !== expectedUrl.pathname) { | ||
return Promise.reject( | ||
new TypeError('Redirected path should match configured path, but got: ' + url.pathname) | ||
) | ||
} | ||
if (!url.search) { | ||
if (!url.query) { | ||
return Promise.reject(new TypeError('Unable to process uri: ' + uri)) | ||
} | ||
var data = Querystring.parse(url.query) | ||
var data = typeof url.query === 'string' ? Querystring.parse(url.query) : (url.query || {}) | ||
var err = getAuthError(data) | ||
@@ -627,4 +631,4 @@ | ||
if (options.state && data.state !== options.state) { | ||
return Promise.reject(new TypeError('Invalid state:' + data.state)) | ||
if (options.state != null && data.state !== options.state) { | ||
return Promise.reject(new TypeError('Invalid state: ' + data.state)) | ||
} | ||
@@ -668,4 +672,4 @@ | ||
* | ||
* @param {string} token A JWT token. | ||
* @param {Object} [options] | ||
* @param {string} token A JWT token. | ||
* @param {Object} [options] | ||
* @return {Promise} | ||
@@ -672,0 +676,0 @@ */ |
/** | ||
* Make a request using `XMLHttpRequest`. | ||
* | ||
* @param {String} method | ||
* @param {String} url | ||
* @param {String} body | ||
* @param {string} method | ||
* @param {string} url | ||
* @param {string} body | ||
* @param {Object} headers | ||
@@ -8,0 +8,0 @@ * @returns {Promise} |
@@ -6,5 +6,5 @@ var popsicle = require('popsicle') | ||
* | ||
* @param {String} method | ||
* @param {String} url | ||
* @param {String} body | ||
* @param {string} method | ||
* @param {string} url | ||
* @param {string} body | ||
* @param {Object} headers | ||
@@ -11,0 +11,0 @@ * @returns {Promise} |
32682
11.75%7
16.67%741
14.18%193
1.58%