From 483b530d3b9956e3abf0beb41ac10052352d2664 Mon Sep 17 00:00:00 2001 From: Amit Agarwal <1344071+labnol@users.noreply.github.com> Date: Thu, 12 May 2022 19:25:36 +0530 Subject: [PATCH] Add pkce parameters in the authorization url Use the `setParam` method of the OAuth2 library to add parameters. Cleaner code! --- samples/Twitter.gs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/samples/Twitter.gs b/samples/Twitter.gs index 691851db..f05814cb 100644 --- a/samples/Twitter.gs +++ b/samples/Twitter.gs @@ -43,8 +43,7 @@ function getService() { var userProps = PropertiesService.getUserProperties(); return OAuth2.createService('Twitter') // Set the endpoint URLs. - .setAuthorizationBaseUrl( - 'https://twitter.com/i/oauth2/authorize?code_challenge_method=S256&code_challenge=' + userProps.getProperty("code_challenge")) + .setAuthorizationBaseUrl('https://twitter.com/i/oauth2/authorize') .setTokenUrl( 'https://api.twitter.com/2/oauth2/token?code_verifier=' + userProps.getProperty("code_verifier")) @@ -61,6 +60,11 @@ function getService() { // Set the scopes to request (space-separated for Twitter services). .setScope('users.read tweet.read offline.access') + + // Add parameters in the authorization url + .setParam('response_type', 'code') + .setParam('code_challenge_method', 'S256') + .setParam('code_challenge', userProps.getProperty("code_challenge")) .setTokenHeaders({ 'Authorization': 'Basic ' + Utilities.base64Encode(CLIENT_ID + ':' + CLIENT_SECRET),