@@ -22,7 +22,7 @@ function run() {
2222 } else {
2323 var authorizationUrl = service . getAuthorizationUrl ( ) ;
2424 Logger . log ( 'Open the following URL and re-run the script: %s' ,
25- authorizationUrl ) ;
25+ authorizationUrl ) ;
2626 }
2727}
2828
@@ -42,34 +42,34 @@ function getService_() {
4242 pkceChallengeVerifier ( ) ;
4343 var userProps = PropertiesService . getUserProperties ( ) ;
4444 return OAuth2 . createService ( 'Twitter' )
45- // Set the endpoint URLs.
46- . setAuthorizationBaseUrl ( 'https://twitter.com/i/oauth2/authorize' )
47- . setTokenUrl (
48- 'https://api.twitter.com/2/oauth2/token?code_verifier=' + userProps . getProperty ( " code_verifier" ) )
45+ // Set the endpoint URLs.
46+ . setAuthorizationBaseUrl ( 'https://twitter.com/i/oauth2/authorize' )
47+ . setTokenUrl (
48+ 'https://api.twitter.com/2/oauth2/token?code_verifier=' + userProps . getProperty ( ' code_verifier' ) )
4949
50- // Set the client ID and secret.
51- . setClientId ( CLIENT_ID )
52- . setClientSecret ( CLIENT_SECRET )
50+ // Set the client ID and secret.
51+ . setClientId ( CLIENT_ID )
52+ . setClientSecret ( CLIENT_SECRET )
5353
54- // Set the name of the callback function that should be invoked to
55- // complete the OAuth flow.
56- . setCallbackFunction ( 'authCallback' )
54+ // Set the name of the callback function that should be invoked to
55+ // complete the OAuth flow.
56+ . setCallbackFunction ( 'authCallback' )
5757
58- // Set the property store where authorized tokens should be persisted.
59- . setPropertyStore ( userProps )
58+ // Set the property store where authorized tokens should be persisted.
59+ . setPropertyStore ( userProps )
6060
61- // Set the scopes to request (space-separated for Twitter services).
62- . setScope ( 'users.read tweet.read offline.access' )
63-
64- // Add parameters in the authorization url
65- . setParam ( 'response_type' , 'code' )
66- . setParam ( 'code_challenge_method' , 'S256' )
67- . setParam ( 'code_challenge' , userProps . getProperty ( "code_challenge" ) )
61+ // Set the scopes to request (space-separated for Twitter services).
62+ . setScope ( 'users.read tweet.read offline.access' )
6863
69- . setTokenHeaders ( {
70- 'Authorization' : 'Basic ' + Utilities . base64Encode ( CLIENT_ID + ':' + CLIENT_SECRET ) ,
71- 'Content-Type' : 'application/x-www-form-urlencoded'
72- } )
64+ // Add parameters in the authorization url
65+ . setParam ( 'response_type' , 'code' )
66+ . setParam ( 'code_challenge_method' , 'S256' )
67+ . setParam ( 'code_challenge' , userProps . getProperty ( 'code_challenge' ) )
68+
69+ . setTokenHeaders ( {
70+ 'Authorization' : 'Basic ' + Utilities . base64Encode ( CLIENT_ID + ':' + CLIENT_SECRET ) ,
71+ 'Content-Type' : 'application/x-www-form-urlencoded'
72+ } ) ;
7373}
7474
7575/**
@@ -97,21 +97,21 @@ function logRedirectUri() {
9797 */
9898function pkceChallengeVerifier ( ) {
9999 var userProps = PropertiesService . getUserProperties ( ) ;
100- if ( ! userProps . getProperty ( " code_verifier" ) ) {
101- var verifier = "" ;
102- var possible = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~" ;
100+ if ( ! userProps . getProperty ( ' code_verifier' ) ) {
101+ var verifier = '' ;
102+ var possible = ' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~' ;
103103
104104 for ( var i = 0 ; i < 128 ; i ++ ) {
105105 verifier += possible . charAt ( Math . floor ( Math . random ( ) * possible . length ) ) ;
106106 }
107107
108- var sha256Hash = Utilities . computeDigest ( Utilities . DigestAlgorithm . SHA_256 , verifier )
108+ var sha256Hash = Utilities . computeDigest ( Utilities . DigestAlgorithm . SHA_256 , verifier ) ;
109109
110110 var challenge = Utilities . base64Encode ( sha256Hash )
111- . replace ( / \+ / g, '-' )
112- . replace ( / \/ / g, '_' )
113- . replace ( / = + $ / , '' )
114- userProps . setProperty ( " code_verifier" , verifier )
115- userProps . setProperty ( " code_challenge" , challenge )
111+ . replace ( / \+ / g, '-' )
112+ . replace ( / \/ / g, '_' )
113+ . replace ( / = + $ / , '' ) ;
114+ userProps . setProperty ( ' code_verifier' , verifier ) ;
115+ userProps . setProperty ( ' code_challenge' , challenge ) ;
116116 }
117117}
0 commit comments