@@ -31,7 +31,7 @@ const APP_AUTH_OAUTH_SCOPES = ['https://www.googleapis.com/auth/chat.bot'];
3131// User authentication
3232const CLIENT_SECRETS_FILE = './credentials.json' ;
3333const CLIENT_SECRETS = JSON . parse (
34- await readFile ( new URL ( CLIENT_SECRETS_FILE , import . meta. url ) , 'utf8' ) ,
34+ await readFile ( new URL ( CLIENT_SECRETS_FILE , import . meta. url ) , 'utf8' ) ,
3535) . web ;
3636
3737/**
@@ -73,9 +73,9 @@ function getAuthenticatedUserOAuth2Client(scopes) {
7373 return new Promise ( ( resolve , reject ) => {
7474 // Create a client based on client secrets
7575 const oAuth2Client = new OAuth2Client (
76- CLIENT_SECRETS . client_id ,
77- CLIENT_SECRETS . client_secret ,
78- CLIENT_SECRETS . redirect_uris [ 0 ] ,
76+ CLIENT_SECRETS . client_id ,
77+ CLIENT_SECRETS . client_secret ,
78+ CLIENT_SECRETS . redirect_uris [ 0 ] ,
7979 ) ;
8080
8181 // Generate the URL to use for consent
@@ -86,31 +86,31 @@ function getAuthenticatedUserOAuth2Client(scopes) {
8686
8787 // Open an HTTP server to accept the OAuth2 callback
8888 const server = http
89- . createServer ( async ( request , response ) => {
90- try {
91- if ( request . url . indexOf ( '/oauth2callback' ) > - 1 ) {
89+ . createServer ( async ( request , response ) => {
90+ try {
91+ if ( request . url . indexOf ( '/oauth2callback' ) > - 1 ) {
9292 // Acquire the code and close the server.
93- const queryString = new url . URL (
94- request . url ,
95- 'http://localhost:3000' ,
96- ) . searchParams ;
97- const code = queryString . get ( 'code' ) ;
98- response . end ( 'Done!' ) ;
99- server . destroy ( ) ;
100- // Acquire the tokens
101- const r = await oAuth2Client . getToken ( code ) ;
102- // Update credentials of the OAuth2 client.
103- oAuth2Client . setCredentials ( r . tokens ) ;
104- resolve ( oAuth2Client ) ;
105- }
106- } catch ( e ) {
107- reject ( e ) ;
93+ const queryString = new url . URL (
94+ request . url ,
95+ 'http://localhost:3000' ,
96+ ) . searchParams ;
97+ const code = queryString . get ( 'code' ) ;
98+ response . end ( 'Done!' ) ;
99+ server . destroy ( ) ;
100+ // Acquire the tokens
101+ const r = await oAuth2Client . getToken ( code ) ;
102+ // Update credentials of the OAuth2 client.
103+ oAuth2Client . setCredentials ( r . tokens ) ;
104+ resolve ( oAuth2Client ) ;
108105 }
109- } )
110- . listen ( 3000 , ( ) => {
106+ } catch ( e ) {
107+ reject ( e ) ;
108+ }
109+ } )
110+ . listen ( 3000 , ( ) => {
111111 // Open default browser and start the flow
112- open ( authorizeUrl , { wait : false } ) . then ( ( cp ) => cp . unref ( ) ) ;
113- } ) ;
112+ open ( authorizeUrl , { wait : false } ) . then ( ( cp ) => cp . unref ( ) ) ;
113+ } ) ;
114114 destroyer ( server ) ;
115115 } ) ;
116116}
0 commit comments