GoogleSheetsWrapper icon indicating copy to clipboard operation
GoogleSheetsWrapper copied to clipboard

Add OAuth 2.0 user authentication support for accessing organization Shared Drives

Open Copilot opened this issue 2 months ago • 0 comments

Service accounts cannot access Shared Drives restricted to organization members. This adds OAuth 2.0 user credential support alongside existing service account authentication.

Changes

Core API additions:

  • SheetHelper, SheetAppender, SheetExporter:
    • New Init(ICredential) overload accepts any credential type (OAuth UserCredential, ServiceAccountCredential, etc.)
    • New constructor overload (spreadsheetID, tabName) for credentials that don't require service account email

Documentation:

  • Added OAuth 2.0 setup guide with GoogleWebAuthorizationBroker flow
  • Clarified when to use each authentication method

Usage

OAuth 2.0 (new):

UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
    GoogleClientSecrets.FromStream(stream).Secrets,
    new[] { SheetsService.Scope.Spreadsheets },
    "user", CancellationToken.None);

var sheetHelper = new SheetHelper<TestRecord>(spreadsheetId, tabName);
sheetHelper.Init(credential);

Service Account (unchanged):

var sheetHelper = new SheetHelper<TestRecord>(spreadsheetId, serviceAccountEmail, tabName);
sheetHelper.Init(jsonCredentials);

All existing service account code continues to work without modification.

Original prompt

This section details on the original issue you should resolve

<issue_title>Alternative authentication methods (to service accounts)</issue_title> <issue_description>At the moment, we can only authenticate with service accounts.

The problem is that service accounts cannot access Shared Drives because it is restricted to members of the organization / domain.

Is it possible to authenticate via other methods (e.g. user accounts with OAuth)? </issue_description>

Comments on the Issue (you are @copilot in this section)

@SteveWinward @rohan-gaitonde today this library only supports service account authentication. The native Google Sheets API does support this so it is possible to configure this, just not supported today in the GoogleSheetsWrapper API.

I'm tagging this with the enhancement label so if anyone has the cycles to implement this into this library they can create a pull request for it. </comment_new>

  • Fixes SteveWinward/GoogleSheetsWrapper#39

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot avatar Dec 17 '25 20:12 Copilot