# GoogleServiceAccountCredentialSource

Credential source that acquires Google access tokens by exchanging a signed service-account JWT assertion.

Class 

`OfficeIMO.GoogleWorkspace`

**Namespace**

`OfficeIMO.GoogleWorkspace`

**Assembly**

`OfficeIMO.GoogleWorkspace`

**Source revision**

`be6c300e4ab1` with working tree changes

**Source**

[GoogleServiceAccountCredentialSource.cs:14](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/Sources/OfficeIMO.GoogleWorkspace/GoogleServiceAccountCredentialSource.cs#L14)

**Implements**

`IGoogleWorkspaceCredentialSource` `IDisposable`

**Modifiers**

sealed

Credential source that acquires Google access tokens by exchanging a signed service-account JWT assertion.

## Inheritance

- object
- GoogleServiceAccountCredentialSource

## Guides & Samples

Authored walkthroughs and practical samples linked to this API.

- [Authenticate to Google Workspace](/docs/google-workspace/authentication/) Guide
  
  Create a GoogleWorkspaceSession in .NET from a service account, a short-lived access token, or existing Google APIs credentials.
- [Export Office Documents to Google Workspace](/docs/google-workspace/) Guide
  
  Export Word, Excel, and PowerPoint documents to Google Docs, Sheets, and Slides, import them back, and work with Drive through one shared session.
- [Export and Import Google Docs](/docs/google-workspace/docs/) Guide
  
  Plan a Word-to-Google-Docs export offline, create a Google Doc from a WordDocument, import a Google Doc, and replace an existing one safely.
- [Export and Import Google Sheets](/docs/google-workspace/sheets/) Guide
  
  Plan an Excel-to-Google-Sheets export offline, create a spreadsheet from an ExcelDocument, import a Google Sheet, and replace an existing one safely.
- [Export and Import Google Slides](/docs/google-workspace/slides/) Guide
  
  Plan a PowerPoint-to-Google-Slides export, create a presentation from a PowerPointDocument, and import or replace Google Slides safely.
- [Manage Google Drive Files](/docs/google-workspace/drive/) Guide
  
  List, upload, download, copy, and share Google Drive files with the typed GoogleDriveClient from OfficeIMO.GoogleWorkspace.Drive.

## Usage

Explore 2 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

### Returned or exposed by 2

- Method [GoogleServiceAccountCredentialSource.FromFile](/api/google-workspace/officeimo-googleworkspace-googleserviceaccountcredentialsource/#method-fromfile-string-officeimo-googleworkspace-googleworkspacesessionoptions)
- Method [GoogleServiceAccountCredentialSource.FromJson](/api/google-workspace/officeimo-googleworkspace-googleserviceaccountcredentialsource/#method-fromjson-string-officeimo-googleworkspace-googleworkspacesessionoptions)

Filter members 

Show inherited

## Constructors

`public GoogleServiceAccountCredentialSource(string clientEmail, string privateKeyPem, string? tokenEndpoint = null, GoogleWorkspaceSessionOptions? sessionOptions = null)` [#](#constructor-ctor-string-string-string-officeimo-googleworkspace-googleworkspacesessionoptions)

[GoogleServiceAccountCredentialSource.cs:14](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/Sources/OfficeIMO.GoogleWorkspace/GoogleServiceAccountCredentialSource.cs#L14)

Creates a service-account credential source from an email identity and PKCS#8 PEM private key.

Parameters

**clientEmail string required**

Service-account email used as the JWT issuer.

**privateKeyPem string required**

RSA private key in PEM form used to sign JWT assertions.

**tokenEndpoint string? = null optional**

OAuth token endpoint, or null for Google's default endpoint.

**sessionOptions OfficeIMO.GoogleWorkspace.GoogleWorkspaceSessionOptions? = null optional**

Optional delegation, HTTP-client, and timeout settings.

## Methods

`public async Task<GoogleWorkspaceAccessToken> AcquireAccessTokenAsync(IEnumerable<string> scopes, CancellationToken cancellationToken = default)` [#](#method-acquireaccesstokenasync-collections-generic-ienumerable-system-string-threading-cancellationtoken)

Acquires an access token and its available scope evidence for the requested operation.

Parameters

**scopes System.Collections.Generic.IEnumerable<string> required**

OAuth scopes required by the pending operation.

**cancellationToken System.Threading.CancellationToken = default optional**

Token used to cancel acquisition.

Returns

`Task<GoogleWorkspaceAccessToken>` A task that produces the acquired token and its scope and identity evidence. Callers must verify that the evidence covers their required scopes.

`public void Dispose()` [#](#method-dispose)

[GoogleServiceAccountCredentialSource.cs:129](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/Sources/OfficeIMO.GoogleWorkspace/GoogleServiceAccountCredentialSource.cs#L129)

Releases the token-cache lock and the internally created HTTP client, if any.

`public static GoogleServiceAccountCredentialSource FromFile(string serviceAccountJsonPath, GoogleWorkspaceSessionOptions? sessionOptions = null)` [#](#method-fromfile-string-officeimo-googleworkspace-googleworkspacesessionoptions)

[GoogleServiceAccountCredentialSource.cs:99](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/Sources/OfficeIMO.GoogleWorkspace/GoogleServiceAccountCredentialSource.cs#L99)

Creates a credential source from a Google service-account JSON file.

Parameters

**serviceAccountJsonPath string required**

Path to the service-account JSON file.

**sessionOptions OfficeIMO.GoogleWorkspace.GoogleWorkspaceSessionOptions? = null optional**

Optional delegation, HTTP-client, and timeout settings.

Returns

`GoogleServiceAccountCredentialSource` A configured credential source.

`public static GoogleServiceAccountCredentialSource FromJson(string serviceAccountJson, GoogleWorkspaceSessionOptions? sessionOptions = null)` [#](#method-fromjson-string-officeimo-googleworkspace-googleworkspacesessionoptions)

[GoogleServiceAccountCredentialSource.cs:74](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/Sources/OfficeIMO.GoogleWorkspace/GoogleServiceAccountCredentialSource.cs#L74)

Creates a credential source from a Google service-account JSON document.

Parameters

**serviceAccountJson string required**

JSON containing client_email, private_key, and optionally token_uri.

**sessionOptions OfficeIMO.GoogleWorkspace.GoogleWorkspaceSessionOptions? = null optional**

Optional delegation, HTTP-client, and timeout settings.

Returns

`GoogleServiceAccountCredentialSource` A configured credential source.

## Inherited Methods

`public virtual bool Equals(object? obj)` [#](#method-equals-object)

Inherited from object

Parameters

**obj object? required**

Returns

`bool`

`public virtual int GetHashCode()` [#](#method-gethashcode)

Inherited from object

Returns

`int`

`public Type GetType()` [#](#method-gettype)

Inherited from object

Returns

`Type`

`public virtual string? ToString()` [#](#method-tostring)

Inherited from object

Returns

`string?`

## Properties

`public string ClientEmail { get; }` [#](#property-clientemail)

[GoogleServiceAccountCredentialSource.cs:54](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/Sources/OfficeIMO.GoogleWorkspace/GoogleServiceAccountCredentialSource.cs#L54)

Gets the service-account email used as the JWT issuer.

`public string TokenEndpoint { get; }` [#](#property-tokenendpoint)

[GoogleServiceAccountCredentialSource.cs:56](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/Sources/OfficeIMO.GoogleWorkspace/GoogleServiceAccountCredentialSource.cs#L56)

Gets the OAuth endpoint used to exchange signed JWT assertions.

`public string? SubjectUser { get; }` [#](#property-subjectuser)

[GoogleServiceAccountCredentialSource.cs:58](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/Sources/OfficeIMO.GoogleWorkspace/GoogleServiceAccountCredentialSource.cs#L58)

Gets the Workspace user to impersonate when domain-wide delegation is enabled.

`public bool UseDomainWideDelegation { get; }` [#](#property-usedomainwidedelegation)

[GoogleServiceAccountCredentialSource.cs:61](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/Sources/OfficeIMO.GoogleWorkspace/GoogleServiceAccountCredentialSource.cs#L61)

Gets whether domain-wide delegation was requested for generated JWT assertions.

`public TimeSpan TokenLifetime { get; }` [#](#property-tokenlifetime)

[GoogleServiceAccountCredentialSource.cs:63](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/Sources/OfficeIMO.GoogleWorkspace/GoogleServiceAccountCredentialSource.cs#L63)

Gets the requested lifetime of signed JWT assertions and fallback access-token lifetime.

`public TimeSpan RefreshSkew { get; }` [#](#property-refreshskew)

[GoogleServiceAccountCredentialSource.cs:65](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/Sources/OfficeIMO.GoogleWorkspace/GoogleServiceAccountCredentialSource.cs#L65)

Gets how early a cached token is refreshed before its expiry.

<!-- PowerForge markdown artifact sha256:B4F40581A5E2F819B8BE2C92AC4A659E30952D3251F547A3C2E8032BBE8152F0 -->
