Skip to content

fix: issue with refreshing token when client_secret is not set #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dist/OAuth2.gs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,6 @@ Service_.prototype.ensureExpiresAtSet_ = function(token) {
Service_.prototype.refresh = function() {
validate_({
'Client ID': this.clientId_,
'Client Secret': this.clientSecret_,
'Token URL': this.tokenUrl_
});

Expand Down
1 change: 0 additions & 1 deletion src/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,6 @@ Service_.prototype.ensureExpiresAtSet_ = function(token) {
Service_.prototype.refresh = function() {
validate_({
'Client ID': this.clientId_,
'Client Secret': this.clientSecret_,
'Token URL': this.tokenUrl_
});

Expand Down
29 changes: 29 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,35 @@ describe('Service', () => {
done();
});

it('should refresh token granted for PKCE', () => {
const NOW_SECONDS = OAuth2.getTimeInSeconds_(new Date());
const ONE_HOUR_AGO_SECONDS = NOW_SECONDS - 360;
var token = {
granted_time: ONE_HOUR_AGO_SECONDS,
expires_in: 100,
refresh_token: 'bar',
refresh_token_expires_in: 720
};
var properties = new MockProperties({
'oauth2.test': JSON.stringify(token)
});

mocks.UrlFetchApp.resultFunction = () => JSON.stringify({
access_token: Math.random().toString(36)
});

OAuth2.createService('test')
.setClientId('test')
.setTokenUrl('http://www.example.com')
.setPropertyStore(properties)
.generateCodeVerifier()
.refresh();

var storedToken = JSON.parse(properties.getProperty('oauth2.test'));
assert.equal(storedToken.refresh_token, 'bar');
assert.equal(storedToken.refreshTokenExpiresAt, NOW_SECONDS + 360);
});

it('should retain refresh expiry', () => {
const NOW_SECONDS = OAuth2.getTimeInSeconds_(new Date());
const ONE_HOUR_AGO_SECONDS = NOW_SECONDS - 360;
Expand Down