Credentials

Using a Fetched Access Token

Pass the access token returned by FetchAccessToken to RESTClient as a Bearer token to call the provider's API directly.

Pass the access token returned by FetchAccessToken to RESTClient as a Bearer token to call the provider's API directly.

FetchAccessToken(out string accessToken) (see OAuth and Service Account) returns a short-lived bearer token for Google, Azure, or AWS. Pass it to GPAL.RESTClient.WithHeader("Authorization", "Bearer " + accessToken) to call the provider's REST API directly, for endpoints not already covered by GoogleSheets, GoogleDrive, or GoogleDorking.

Examples

GPAL Fluent: High-level fluent C# API

//WithHeader adds the Authorization header to the request. This pattern works for any Google/Azure/AWS REST endpoint not already wrapped by a GPAL subsystem (GoogleSheets, GoogleDrive, GoogleDorking).

// Fetch an access token, then call a REST API with it directly GPAL.CredentialsFor(CredentialServiceType.Google) .WithUsername("you@example.com") .WithPassword("your-password") .WithServiceAccountKey(GPAL.FileFor("service-account.json")) .WithScope(OAuthScope.Google_Drive) .FetchAccessToken(out string accessToken); GPAL.RESTClient .WithAPIBase("https://www.googleapis.com") .WithEndpoint("/drive/v3/about?fields=user") .WithHeader("Authorization", "Bearer " + accessToken) .Execute();