How to connect to Google Calendar API using service account using Node.js?
P粉921130067
P粉921130067 2023-08-17 23:52:59
0
1
549
<p>How to use the Google Auth client when using Node.js. </p> <p>I checked many articles that the client URL will provide a code data that I can use to get the client details. However, how can I use a service client to automatically authenticate on behalf of the client. I mainly need to get the Google Meet link and add it to the client's Google calendar. </p> <p>I am following this code. But this is manual URL authentication. </p> <p>https://github.com/isuruhettiarachchi/ssd-oauth-assignment/blob/master/utils/google-util.js</p>
P粉921130067
P粉921130067

reply all(1)
P粉920835423

Try something like the following, making sure domain-wide delegation is configured from your workspace account to the service account.

subject is the user on the domain you want the service account to impersonate.

let google = require('googleapis');
let privateKey = require("./privatekey.json");

var jwtClient = new google.auth.JWT({
       email: privateKey.client_email,
       key: privateKey.private_key,
       scopes: ['https://www.googleapis.com/auth/calendar'],
       subject: 'user@domain.com'
    });

jwtClient.authorize(function (error, tokens) {
  if (error) {
    console.log(error);
    return;
  } 
  else {
    console.log("Successfully connected!");
  }
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template