client-oauth2
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -330,3 +330,3 @@ /* global define */ | ||
ClientOAuth2.prototype._request = function (options) { | ||
return this.request(options) | ||
return this.request(this._requestOptions(options)) | ||
.then(function (res) { | ||
@@ -344,2 +344,9 @@ if (res.status < 200 || res.status >= 399) { | ||
ClientOAuth2.prototype._requestOptions = function (options) { | ||
return assign({ | ||
agent: this.options.agent, | ||
rejectUnauthorized: this.options.rejectUnauthorized | ||
}, options) | ||
} | ||
/** | ||
@@ -428,3 +435,3 @@ * Set `popsicle` as the default request method. | ||
ClientOAuth2Token.prototype.request = function (opts) { | ||
return this.client.request(this.sign(opts)) | ||
return this.client.request(this.client._requestOptions(this.sign(opts))) | ||
} | ||
@@ -431,0 +438,0 @@ |
{ | ||
"name": "client-oauth2", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "Straight-forward library for executing OAuth 2.0 flows and making API requests.", | ||
@@ -38,3 +38,3 @@ "main": "client-oauth2.js", | ||
"karma-cli": "0.0.4", | ||
"karma-coverage": "^0.2.6", | ||
"karma-coverage": "^0.3.1", | ||
"karma-firefox-launcher": "^0.1.3", | ||
@@ -46,6 +46,6 @@ "karma-mocha": "^0.1.9", | ||
"pre-commit": "^1.0.4", | ||
"standard": "^2.6.2" | ||
"standard": "^3.7.2" | ||
}, | ||
"dependencies": { | ||
"popsicle": "^0.3.10" | ||
"popsicle": "^0.5.10" | ||
}, | ||
@@ -52,0 +52,0 @@ "standard": { |
# Client OAuth 2.0 | ||
[![NPM version][npm-image]][npm-url] | ||
[![NPM downloads][downloads-image]][downloads-url] | ||
[![Build status][travis-image]][travis-url] | ||
@@ -22,18 +23,31 @@ | ||
var githubAuth = new ClientOAuth2({ | ||
clientId: 'abc', | ||
clientSecret: '123', | ||
accessTokenUri: 'https://github.com/login/oauth/access_token', | ||
clientId: 'abc', | ||
clientSecret: '123', | ||
accessTokenUri: 'https://github.com/login/oauth/access_token', | ||
authorizationUri: 'https://github.com/login/oauth/authorize', | ||
redirectUri: 'http://example.com/auth/github/callback', | ||
scopes: ['notifications', 'gist'] | ||
}); | ||
authorizationGrants: ['credentials'], | ||
redirectUri: 'http://example.com/auth/github/callback', | ||
scopes: ['notifications', 'gist'] | ||
}) | ||
``` | ||
* **clientId** The client id string assigned to you by the provider | ||
* **clientSecret** The client secret string assigned to you by the provider | ||
* **accessTokenUri** The url to request the access token | ||
* **authorizationUri** The url to redirect users to authenticate with the provider | ||
* **redirectUri** A custom url for the provider to redirect users back to your application | ||
* **scopes** An array of scopes to authenticate against | ||
**Request specific options (node)** | ||
* **rejectUnauthorized** Reject invalid SSL certificates (default: `true`) | ||
* **agent** Custom HTTP pooling agent (default: `infinity-agent`) | ||
To re-create an access token instance and make requests on behalf on the user, you can create an access token instance by using the `createToken` method on a client instance. | ||
```javascript | ||
var token = githubAuth.createToken('accessToken', 'refreshToken'); | ||
var token = githubAuth.createToken('access token', 'optional refresh token', 'optional token type', { optional: 'raw user data' }) | ||
// Refresh the users credentials and save the updated access token. | ||
token.refresh().then(updateToken); | ||
token.refresh().then(updateToken) | ||
@@ -45,7 +59,7 @@ token.request({ | ||
.then(function (res) { | ||
console.log(res); //=> { raw: [Object], body: '...', status: 200, headers: { ... } } | ||
console.log(res) //=> { raw: [Object], body: '...', status: 200, headers: { ... } } | ||
}) | ||
``` | ||
You can override the request mechanism if you need a custom implementation by setting `githubAuth.request = function (opts) { return new Promise(...); }`. You will need to make sure that the custom request mechanism supports the correct input and output objects. | ||
You can override the request mechanism if you need a custom implementation by setting `githubAuth.request = function (opts) { return new Promise(...) }`. You will need to make sure that the custom request mechanism supports the correct input and output objects. | ||
@@ -60,10 +74,10 @@ ### [Authorization Code Grant](http://tools.ietf.org/html/rfc6749#section-4.1) | ||
```javascript | ||
var express = require('express'); | ||
var app = express(); | ||
var express = require('express') | ||
var app = express() | ||
app.get('/auth/github', function (req, res) { | ||
var uri = githubAuth.code.getUri(); | ||
var uri = githubAuth.code.getUri() | ||
res.redirect(uri); | ||
}); | ||
res.redirect(uri) | ||
}) | ||
@@ -73,8 +87,8 @@ app.get('/auth/github/callback', function (req, res) { | ||
.then(function (user) { | ||
console.log(user); //=> { accessToken: '...', tokenType: 'bearer', ... } | ||
console.log(user) //=> { accessToken: '...', tokenType: 'bearer', ... } | ||
// Refresh the current users access token. | ||
user.refresh().then(function (updatedUser) { | ||
console.log(updatedUser === user); //=> true | ||
}); | ||
console.log(updatedUser === user) //=> true | ||
}) | ||
@@ -85,8 +99,8 @@ // Sign API requests on behalf of the current user. | ||
url: 'http://example.com' | ||
}); | ||
}) | ||
// We should store the token into a database. | ||
return res.send(user.accessToken); | ||
}); | ||
}); | ||
return res.send(user.accessToken) | ||
}) | ||
}) | ||
``` | ||
@@ -105,3 +119,3 @@ | ||
.then(function (user) { | ||
console.log(user); //=> { accessToken: '...', tokenType: 'bearer', ... } | ||
console.log(user) //=> { accessToken: '...', tokenType: 'bearer', ... } | ||
@@ -113,9 +127,9 @@ // Make a request to the github API for the current user. | ||
}).then(function (res) { | ||
console.log(res); //=> { body: { ... }, status: 200, headers: { ... } } | ||
}); | ||
}); | ||
}; | ||
console.log(res) //=> { body: { ... }, status: 200, headers: { ... } } | ||
}) | ||
}) | ||
} | ||
// Open the page in a new window, then redirect back to a page that calls our global `oauth2Callback` function. | ||
window.open(githubAuth.token.getUri()); | ||
window.open(githubAuth.token.getUri()) | ||
``` | ||
@@ -132,4 +146,4 @@ | ||
.then(function (user) { | ||
console.log(user); //=> { accessToken: '...', tokenType: 'bearer', ... } | ||
}); | ||
console.log(user) //=> { accessToken: '...', tokenType: 'bearer', ... } | ||
}) | ||
``` | ||
@@ -146,4 +160,4 @@ | ||
.then(function (user) { | ||
console.log(user); //=> { accessToken: '...', tokenType: 'bearer', ... } | ||
}); | ||
console.log(user) //=> { accessToken: '...', tokenType: 'bearer', ... } | ||
}) | ||
``` | ||
@@ -158,4 +172,4 @@ | ||
.then(function (user) { | ||
console.log(user); //=> { accessToken: '...', tokenType: 'bearer', ... } | ||
}); | ||
console.log(user) //=> { accessToken: '...', tokenType: 'bearer', ... } | ||
}) | ||
``` | ||
@@ -169,3 +183,5 @@ | ||
[npm-url]: https://npmjs.org/package/client-oauth2 | ||
[downloads-image]: https://img.shields.io/npm/dm/client-oauth2.svg?style=flat | ||
[downloads-url]: https://npmjs.org/package/client-oauth2 | ||
[travis-image]: https://img.shields.io/travis/mulesoft/js-client-oauth2.svg?style=flat | ||
[travis-url]: https://travis-ci.org/mulesoft/js-client-oauth2 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30645
698
177
+ Addedbuffer-from@1.1.2(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinfinity-agent@1.0.2(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.11.0.0(transitive)
+ Addedpopsicle@0.5.13(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@1.0.342.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstatuses@1.5.0(transitive)
+ Addedstring_decoder@0.10.311.1.1(transitive)
+ Addedthrough2@0.6.5(transitive)
+ Addedtough-cookie@0.12.1(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpopsicle@0.3.11(transitive)
- Removedpsl@1.9.0(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)
Updatedpopsicle@^0.5.10