0

How can I use google auth client using nodejs.

I checked many articles and client URL will provide a code data which I can use for getting client details. but how can i use service client for automatically authenticate on behalf of client.my primary need is to get google meet link and add to clients google calendar.

I was following this code. but is manual url authentication.

https://github.com/isuruhettiarachchi/ssd-oauth-assignment/blob/master/utils/google-util.js

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Sruthi
  • 1
  • Rather than some random github, have you tried googles own documentation? – Jaromanda X Aug 17 '23 at 06:48
  • 1
    Does this answer your question? [Is there is a way to grant my nodejs application access to my google calendar?](https://stackoverflow.com/questions/60929631/is-there-is-a-way-to-grant-my-nodejs-application-access-to-my-google-calendar) – Linda Lawton - DaImTo Aug 17 '23 at 07:23
  • Check out Aurinko API. You can upload your service account key and then create 'managed accounts' that represent users using the service account: https://apirefs.aurinko.io/#tag/Managed-accounts/operation/upsertManagedAccount – Alexey Aug 18 '23 at 12:44

1 Answers1

0

Try something like this make sure to configure domain wide delegation to the service account from your workspace account.

subject is the user on your 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!");
  }
});
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449