Socket
Socket
Sign inDemoInstall

client-oauth2

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

client-oauth2 - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

11

client-oauth2.js

@@ -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 @@

8

package.json
{
"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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc