Open vlucas opened 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
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:
spreadsheetId
: The ID of the Google Spreadsheet.auth
: The authentication instance provided by the user.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:
Yes, this is how it would look exactly! π
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 apeerDependency
, and then let users pass in whatever auth instance they want to. All your package would need to accept in the constructor is aspreadsheetId
andauth
instance.