From 5bf214142f5dbe2a6258bcc3df37f27add43a9e8 Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Mon, 24 Jun 2013 15:47:56 +0200 Subject: [PATCH 1/2] OAuth2 client should allow setting only a refresh token. --- lib/auth/oauth2client.js | 4 ++-- tests/test.oauth2.js | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/lib/auth/oauth2client.js b/lib/auth/oauth2client.js index 58782298fa..b4fb7b97cf 100644 --- a/lib/auth/oauth2client.js +++ b/lib/auth/oauth2client.js @@ -156,8 +156,8 @@ OAuth2Client.prototype.request = var that = this; var credentials = this.credentials; - if (!credentials.access_token) { - throw new Error('No access token is set.'); + if (!credentials.access_token && !credentials.refresh_token) { + throw new Error('No access or refresh token is set.'); } credentials.token_type = credentials.token_type || 'Bearer'; diff --git a/tests/test.oauth2.js b/tests/test.oauth2.js index 33d3c149d6..a8cdd42ff7 100644 --- a/tests/test.oauth2.js +++ b/tests/test.oauth2.js @@ -66,7 +66,7 @@ describe('OAuth2 client', function() { done(); }); - it('should throw exception no access token is set before making ' + + it('should throw exception no access or refresh token is set before making ' + 'a request', function() { var gapis = new googleapis.GoogleApis(); var oauth2client = @@ -80,7 +80,26 @@ describe('OAuth2 client', function() { .newRequest('dummy', {}) .withAuthClient(oauth2client) .execute(); - }, Error, 'No access token is set.'); + }, Error, 'No access or refresh token is set.'); + }); + }); + + it('should not throw any exceptions if only refresh token is set', + function() { + var gapis = new googleapis.GoogleApis(); + var oauth2client = + new googleapis.OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI); + oauth2client.credentials = { refresh_token: 'refresh_token' }; + gapis.Transporter = urlshortenerDiscoveryTransporter; + gapis + .discover('urlshortener', 'v1') + .execute(function(err, client) { + assert.doesNotThrow(function() { + client + .urlshortener.url.list() + .withAuthClient(oauth2client) + .execute(); + }); }); }); @@ -88,15 +107,15 @@ describe('OAuth2 client', function() { var gapis = new googleapis.GoogleApis(); var oauth2client = new googleapis.OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI); - oauth2client.credentials = { access_token: 'foo' }; + oauth2client.credentials = { access_token: 'foo', refresh_token: '' }; gapis - .discover('urlshortener', 'v1') - .execute(function(err, client) { - var req = client.urlshortener.url.list().withAuthClient(oauth2client); - req.execute(function(err, result) { - assert.equal(oauth2client.credentials.token_type, 'Bearer'); - done(); - }); + .discover('urlshortener', 'v1') + .execute(function(err, client) { + var req = client.urlshortener.url.list().withAuthClient(oauth2client); + req.execute(function(err, result) { + assert.equal(oauth2client.credentials.token_type, 'Bearer'); + done(); + }); }); }); From e5c0e1cd08aa70307d98209a434c9496d7027f39 Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Mon, 24 Jun 2013 15:51:21 +0200 Subject: [PATCH 2/2] Incr package version. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8f7dfdc024..dfe74713bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "googleapis", - "version": "0.2.11-alpha", + "version": "0.2.12-alpha", "author": "Google Inc.", "description": "Google APIs Client Library for Node.js", "contributors": [