googleapis
Advanced tools
Comparing version 0.2.2-alpha to 0.2.3-alpha
@@ -64,8 +64,9 @@ /** | ||
* Generates URL for consent page landing. | ||
* @param {object} opts Options. | ||
* @param {object=} opt_opts Options. | ||
* @return {string} URL to consent page. | ||
*/ | ||
OAuth2Client.prototype.generateAuthUrl = function(opts) { | ||
OAuth2Client.prototype.generateAuthUrl = function(opt_opts) { | ||
opts.response_type = 'code'; | ||
var opts = opt_opts || {}; | ||
opts.response_type = opts.response_type || 'code'; | ||
opts.client_id = this.clientId_; | ||
@@ -163,5 +164,5 @@ opts.redirect_uri = this.redirectUri_; | ||
opts.uri += querystring.stringify({ | ||
access_token: credentials.access_token | ||
}); | ||
opts.headers = opts.headers || {}; | ||
opts.headers['Authorization'] | ||
= credentials.token_type + ' ' + credentials.access_token; | ||
@@ -173,16 +174,14 @@ this.transporter.request(opts, function(err, body, res) { | ||
// to multi part batch requests. | ||
for (var i = 0; i < body.length; i++) { | ||
hasAuthError = body[i].error && | ||
(body[i].error.code == 401 || body[i].error.code == 403); | ||
} | ||
err && err.forEach(function(e) { | ||
hasAuthError = (e.code == 401 || e.code == 403); | ||
}); | ||
// if there is an auth error, refresh the token | ||
// and make the request again | ||
if (!opt_dontForceRefresh && hasAuthError && | ||
credentials.refresh_token) { | ||
if (!opt_dontForceRefresh && hasAuthError && credentials.refresh_token) { | ||
// refresh access token and re-request | ||
that.refreshToken_(credentials.refresh_token, function(err, tokens) { | ||
that.refreshToken_(credentials.refresh_token, function(err, result) { | ||
if (err) { | ||
opt_callback && opt_callback(err, null, null); | ||
} else { | ||
var tokens = result; | ||
tokens.refresh_token = credentials.refresh_token; | ||
@@ -189,0 +188,0 @@ that.credentials = tokens; |
{ | ||
"name": "googleapis", | ||
"version": "0.2.2-alpha", | ||
"version": "0.2.3-alpha", | ||
"author": "Google Inc.", | ||
@@ -5,0 +5,0 @@ "description": "Google APIs Client Library for Node.js", |
@@ -67,3 +67,3 @@ /** | ||
new MockTransporter(__dirname + '/data/discovery_urlshortener.json'); | ||
var defaultUserAgent = 'google-api-nodejs-client/0.2.2-alpha'; | ||
var defaultUserAgent = 'google-api-nodejs-client/0.2.3-alpha'; | ||
@@ -208,7 +208,7 @@ it('should set default client user agent if none is set', function() { | ||
var clientId = 'CLIENT_ID'; | ||
var clientSecret = 'CLIENT_SECRET'; | ||
var redirectUrl = 'REDIRECT'; | ||
var accessType = 'offline'; | ||
var scope = 'scopex'; | ||
var CLIENT_ID = 'CLIENT_ID'; | ||
var CLIENT_SECRET = 'CLIENT_SECRET'; | ||
var REDIRECT_URI = 'REDIRECT'; | ||
var ACCESS_TYPE = 'offline'; | ||
var SCOPE = 'scopex'; | ||
@@ -220,8 +220,9 @@ var urlshortenerDiscoveryTransporter = | ||
var opts = { | ||
access_type: accessType, | ||
scope: scope | ||
access_type: ACCESS_TYPE, | ||
scope: SCOPE, | ||
response_type: 'code token' | ||
}; | ||
var oauth2client = | ||
new googleapis.OAuth2Client(clientId, clientSecret, redirectUrl); | ||
new googleapis.OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI); | ||
var generated = oauth2client.generateAuthUrl(opts); | ||
@@ -231,12 +232,24 @@ var parsed = url.parse(generated); | ||
assert.equal(query.access_type, accessType); | ||
assert.equal(query.scope, scope); | ||
assert.equal(query.client_id, clientId); | ||
assert.equal(query.redirect_uri, redirectUrl); | ||
assert.equal(query.response_type, 'code token'); | ||
assert.equal(query.access_type, ACCESS_TYPE); | ||
assert.equal(query.scope, SCOPE); | ||
assert.equal(query.client_id, CLIENT_ID); | ||
assert.equal(query.redirect_uri, REDIRECT_URI); | ||
}); | ||
it('should set resonse_type param to code if none is given while' + | ||
'generating the consent page url', function() { | ||
var oauth2client = | ||
new googleapis.OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI); | ||
var generated = oauth2client.generateAuthUrl(); | ||
var parsed = url.parse(generated); | ||
var query = qs.parse(parsed.query); | ||
assert.equal(query.response_type, 'code'); | ||
}); | ||
it('should throw exception no access token is set before making ' + | ||
'a request', function() { | ||
var oauth2client = | ||
new googleapis.OAuth2Client(clientId, clientSecret, redirectUrl); | ||
new googleapis.OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI); | ||
googleapis.Transporter = urlshortenerDiscoveryTransporter; | ||
@@ -243,0 +256,0 @@ googleapis.load('urlshortener', 'v1', function(err, client) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
109624
18
2648