google-oauth-jwt
Advanced tools
Comparing version 0.1.0 to 0.1.1
var fs = require('fs'), | ||
crypto = require('crypto'), | ||
request = require('request'); | ||
request = require('request'), | ||
debug = require('debug')('google-oauth-jwt'); | ||
@@ -32,6 +33,10 @@ // constants | ||
}, function (err, res, body) { | ||
if (err) { | ||
return callback(err); | ||
} else if (res.statusCode != 200) { | ||
} else { | ||
debug('response from OAuth server: HTTP %d -> %j', res.statusCode, body); | ||
} | ||
if (res.statusCode != 200) { | ||
err = new Error( | ||
@@ -78,2 +83,4 @@ 'failed to obtain an authentication token, request failed with HTTP code ' + | ||
debug('generating jwt for %j', options); | ||
var iat = Math.floor(new Date().getTime() / 1000), | ||
@@ -96,3 +103,3 @@ exp = iat + Math.floor((options.expiration || 60 * 60 * 1000) / 1000), | ||
unsignedJWT = [JWT_header, JWT_claimset].join('.'); | ||
obtainKey(function (err, key) { | ||
@@ -109,2 +116,3 @@ | ||
debug('signed jwt: %s', signedJWT); | ||
return callback(null, signedJWT); | ||
@@ -111,0 +119,0 @@ |
@@ -0,1 +1,3 @@ | ||
var debug = require('debug')('google-oauth-jwt'); | ||
/** | ||
@@ -87,2 +89,3 @@ * A cache of tokens for reusing previously requested tokens until they expire. | ||
this.status = 'expired'; | ||
debug('token is expired, a new token will be requested'); | ||
this.get(callback); | ||
@@ -89,0 +92,0 @@ } else { |
{ | ||
"name": "google-oauth-jwt", | ||
"version": "0.1.0", | ||
"author": { | ||
"name": "Nicolas Mercier", | ||
"email": "nicolas@extrabacon.net" | ||
}, | ||
"description": "Implementation of Google OAuth 2.0 for server-to-server interactions, allowing secure use of Google APIs without interaction from an end-user.", | ||
"keywords": [ | ||
"google", | ||
"api", | ||
"oauth", | ||
"oauth2", | ||
"service account", | ||
"jwt", | ||
"token", | ||
"server to server" | ||
], | ||
"dependencies": { | ||
"request": "*" | ||
}, | ||
"devDependencies": { | ||
"name": "google-oauth-jwt", | ||
"version": "0.1.1", | ||
"author": { | ||
"name": "Nicolas Mercier", | ||
"email": "nicolas@extrabacon.net" | ||
}, | ||
"description": "Implementation of Google OAuth 2.0 for server-to-server interactions, allowing secure use of Google APIs without interaction from an end-user.", | ||
"keywords": [ | ||
"google", | ||
"api", | ||
"oauth", | ||
"oauth2", | ||
"service account", | ||
"jwt", | ||
"token", | ||
"server to server" | ||
], | ||
"dependencies": { | ||
"request": "*", | ||
"debug": "~0.7.2" | ||
}, | ||
"devDependencies": { | ||
"underscore": "*", | ||
"async": "*", | ||
"mocha": "*", | ||
"chai": "*", | ||
"chai-spies": "*" | ||
}, | ||
"scripts": { | ||
"test": "mocha test/*.js -t 5000" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/extrabacon/google-oauth-jwt" | ||
}, | ||
"homepage": "http://github.com/extrabacon/google-oauth-jwt", | ||
"bugs": "http://github.com/extrabacon/google-oauth-jwt/issues", | ||
"engines": { | ||
"node": ">=0.8" | ||
} | ||
"mocha": "*", | ||
"chai": "*", | ||
"chai-spies": "*" | ||
}, | ||
"scripts": { | ||
"test": "mocha test/*.js -t 5000" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/extrabacon/google-oauth-jwt" | ||
}, | ||
"homepage": "http://github.com/extrabacon/google-oauth-jwt", | ||
"bugs": "http://github.com/extrabacon/google-oauth-jwt/issues", | ||
"engines": { | ||
"node": ">=0.8" | ||
} | ||
} |
@@ -72,3 +72,3 @@ # google-oauth-jwt | ||
In this example, we use a modified instance of [request](https://github.com/mikeal/request) to query the | ||
Google Drive API. `request` is a full-featured HTTP client which will be augmented with Google OAuth2 capabilities by using the `requestWithJWT` method. The modified module will request and cache tokens automatically when supplied with a `jwt` setting in the options. | ||
Google Drive API. [request](https://github.com/mikeal/request) is a full-featured HTTP client which can be extended with Google OAuth2 capabilities by using the `requestWithJWT` method. The modified module will request and cache tokens automatically when supplied with a `jwt` setting in the options. | ||
@@ -94,5 +94,4 @@ ```javascript | ||
Note that the `options` object includes a `jwt` object we use to configure how to encode the JWT. The token will then | ||
automatically be requested and inserted in the authorization header for this API call. It will also be cached and | ||
reused for subsequent calls using the same service account and scopes. | ||
Note that the `options` object includes a `jwt` object we use to configure the JWT generation. The token will then | ||
automatically be requested and inserted in the authorization header. It will also be cached and reused for subsequent calls using the same service account and scopes. | ||
@@ -243,4 +242,16 @@ If you want to use a specific version of `request`, simply pass it to the the `requestWithJWT` method as such: | ||
## Debugging | ||
To turn on debugging, add "google-oauth-jwt" to your `DEBUG` variable. Debugging events include JWT generation, token | ||
requests to the OAuth server and token expirations through `TokenCache`. | ||
For example, to turn on debugging while running the unit tests, use this: | ||
```bash | ||
DEBUG=google-oauth-jwt mocha -t 5000 | ||
``` | ||
## Changelog | ||
* 0.1.1: re-introduced debugging, now with [debug](https://github.com/visionmedia/debug) | ||
* 0.1.0: improved documentation, introduced unit tests and refactoring aimed at testability | ||
@@ -247,0 +258,0 @@ * 0.0.7: fixed token expiration check |
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
35375
495
295
0
2
+ Addeddebug@~0.7.2
+ Addeddebug@0.7.4(transitive)