Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Auth Options #5

Open
vlucas opened this issue Jul 25, 2024 · 3 comments
Open

More Auth Options #5

vlucas opened this issue Jul 25, 2024 · 3 comments

Comments

@vlucas
Copy link

vlucas commented Jul 25, 2024

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
Copy link
Member

teles commented Jul 25, 2024

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
Copy link
Member

teles commented Jul 25, 2024

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:

  • 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:

  • Flexibility to use different authentication methods.
  • Enables the use of OAuth for operations on behalf of users.
  • Improves the package's usability for Google Sheets Add-Ons.

@vlucas
Copy link
Author

vlucas commented Jul 26, 2024

Yes, this is how it would look exactly! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants