Skip to content

Commit aae9287

Browse files
fix: issue with refreshing token when client_secret is not set (#513)
* Fix issue with refreshing token when client_secret is not set * check that refreshed token has refreshTokenExpiresAt set
1 parent f57c727 commit aae9287

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

dist/OAuth2.gs

-1
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,6 @@ Service_.prototype.ensureExpiresAtSet_ = function(token) {
759759
Service_.prototype.refresh = function() {
760760
validate_({
761761
'Client ID': this.clientId_,
762-
'Client Secret': this.clientSecret_,
763762
'Token URL': this.tokenUrl_
764763
});
765764

src/Service.js

-1
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@ Service_.prototype.ensureExpiresAtSet_ = function(token) {
666666
Service_.prototype.refresh = function() {
667667
validate_({
668668
'Client ID': this.clientId_,
669-
'Client Secret': this.clientSecret_,
670669
'Token URL': this.tokenUrl_
671670
});
672671

test/test.js

+29
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,35 @@ describe('Service', () => {
387387
done();
388388
});
389389

390+
it('should refresh token granted for PKCE', () => {
391+
const NOW_SECONDS = OAuth2.getTimeInSeconds_(new Date());
392+
const ONE_HOUR_AGO_SECONDS = NOW_SECONDS - 360;
393+
var token = {
394+
granted_time: ONE_HOUR_AGO_SECONDS,
395+
expires_in: 100,
396+
refresh_token: 'bar',
397+
refresh_token_expires_in: 720
398+
};
399+
var properties = new MockProperties({
400+
'oauth2.test': JSON.stringify(token)
401+
});
402+
403+
mocks.UrlFetchApp.resultFunction = () => JSON.stringify({
404+
access_token: Math.random().toString(36)
405+
});
406+
407+
OAuth2.createService('test')
408+
.setClientId('test')
409+
.setTokenUrl('http://www.example.com')
410+
.setPropertyStore(properties)
411+
.generateCodeVerifier()
412+
.refresh();
413+
414+
var storedToken = JSON.parse(properties.getProperty('oauth2.test'));
415+
assert.equal(storedToken.refresh_token, 'bar');
416+
assert.equal(storedToken.refreshTokenExpiresAt, NOW_SECONDS + 360);
417+
});
418+
390419
it('should retain refresh expiry', () => {
391420
const NOW_SECONDS = OAuth2.getTimeInSeconds_(new Date());
392421
const ONE_HOUR_AGO_SECONDS = NOW_SECONDS - 360;

0 commit comments

Comments
 (0)