holy-sheets / holysheets

πŸ‘ΌπŸ» HollySheets is a TypeScript library that simplifies the process of interacting with Google Sheets API. It provides a set of tools to read and write data from and to Google Sheets.
https://holy-sheets.github.io/
MIT License
3 stars 0 forks source link

More Auth Options #5

Open vlucas opened 2 months ago

vlucas commented 2 months ago

I am writing a Google Sheets Add-On, but I cannot use your awesome package because of how you have limited auth to JWT only. I use oAuth to do operations on my users behalf.

A better solution might be to pull the google-auth-library out of your package, make it a peerDependency, and then let users pass in whatever auth instance they want to. All your package would need to accept in the constructor is a spreadsheetId and auth instance.

teles commented 2 months ago

Hi, @vlucas !

Thank you for your feedback and for using Holysheets!

I understand your concern regarding the limitation of authentication to JWT only. Your suggestion to pull out google-auth-library and make it a peerDependency, allowing users to pass their own auth instance, is a great idea. This would indeed provide more flexibility for users who need to use OAuth for their Google Sheets operations.

I will create a task to implement this feature. Your suggestion will help improve the package for everyone.

Best regards

teles commented 2 months ago

Enhancement: Allow Custom Auth Instances for Google Sheets

Current Behavior: The current implementation of Holysheets limits authentication to JWT only, using google-auth-library directly.

Proposed Improvement: Pull google-auth-library out of the package and make it a peerDependency. Allow users to pass their own authentication instance to the Holysheets constructor. This change will enable the use of OAuth and other authentication methods, providing more flexibility for users who need to perform operations on behalf of their users.

New Constructor Parameters:

Example Usage:

const { google } = require('googleapis');
const Holysheets = require('holysheets');

const auth = new google.auth.OAuth2(
  YOUR_CLIENT_ID,
  YOUR_CLIENT_SECRET,
  YOUR_REDIRECT_URL
);

// After obtaining the OAuth2 tokens
auth.setCredentials({
  access_token: ACCESS_TOKEN,
  refresh_token: REFRESH_TOKEN,
  scope: SCOPES,
  token_type: TOKEN_TYPE,
  expiry_date: EXPIRY_DATE
});

const sheets = new Holysheets({
  spreadsheetId: 'your-spreadsheet-id',
  auth: auth
});

// Use the `sheets` instance as usual

Benefits:

vlucas commented 2 months ago

Yes, this is how it would look exactly! πŸ‘