Google_GenerativeAI.Auth
2.0.2
See the version list below for details.
dotnet add package Google_GenerativeAI.Auth --version 2.0.2
NuGet\Install-Package Google_GenerativeAI.Auth -Version 2.0.2
<PackageReference Include="Google_GenerativeAI.Auth" Version="2.0.2" />
paket add Google_GenerativeAI.Auth --version 2.0.2
#r "nuget: Google_GenerativeAI.Auth, 2.0.2"
// Install Google_GenerativeAI.Auth as a Cake Addin #addin nuget:?package=Google_GenerativeAI.Auth&version=2.0.2 // Install Google_GenerativeAI.Auth as a Cake Tool #tool nuget:?package=Google_GenerativeAI.Auth&version=2.0.2
Google_GenerativeAI.Auth
Google_GenerativeAI.Auth
is a helper library for the Unofficial C# Google Generative AI SDK (Google Gemini) that simplifies authentication using OAuth and Service Accounts. It provides concrete implementations for the IGoogleAuthenticator
interface, making it easy to integrate authentication into your applications using the SDK. This library handles the complexities of obtaining access tokens, so you can focus on building generative AI applications.
Features
- Service Account Authentication: Authenticate using Google Service Accounts, either with a JSON key file or with a key and password.
IGoogleAuthenticator
Implementation: Seamlessly integrates with the Google Generative AI SDK by implementing theIGoogleAuthenticator
interface.- Easy-to-Use API: Provides simple methods for creating authenticators and retrieving access tokens.
- Asynchronous Support: Uses
async/await
for non-blocking, asynchronous operations.
Installation
Install the Google_GenerativeAI.Auth
NuGet package:
dotnet add package Google_GenerativeAI.Auth
You will also need to install the main Google Generative AI SDK:
dotnet add package Google_GenerativeAI
Usage
The Google_GenerativeAI.Auth library provides two main ways to authenticate with a service account:
Using a JSON Key File (Recommended):
Uses the path to a service account JSON key file. This is the preferred method for most use cases.Using Key and Password:
Requires the service account email, key, and password.
1. Service Account Authentication (JSON Key File)
This is the recommended approach. Download a JSON key file for your service account from the Google Cloud Console. Keep this file secure!
// Assuming 'jsonFilePath' is the path to your service account JSON key file.
var authenticator = new GoogleServiceAccountAuthenticator(jsonFilePath);
var vertexAi = new VertexAIModel(authenticator: authenticator);
Important: jsonFilePath
should be the full path to your JSON key file. Do not hardcode this path. Instead, retrieve it from an environment variable or a secure configuration store:
2. Service Account Authentication (Key and Password)
This method is less common and requires careful handling of the credentials.
// Assuming 'email', 'key', and 'password' are your service account credentials.
var authenticator = new GoogleServiceAccountAuthenticator(email, key, password);
var vertexAi = new VertexAIModel(authenticator: authenticator);
Important: email
, key
, and password
should be your actual service account credentials. Do not hardcode these values. Use environment variables or a secure configuration system:
2. OAuth Authentication with Client Secret and Client Id
// Assuming 'credentialFile' your client_secret.json file.
var authenticator = new GoogleOAuthAuthenticator(credentialFile);
var vertexAi = new VertexAIModel(authenticator: authenticator);
Getting the Access Token Directly
You can get the access token directly from the IGoogleAuthenticator
if needed:
var token = await authenticator.GetAccessTokenAsync();
Console.WriteLine(token.AccessToken); // Use the token as needed.
Important Security Considerations
- NEVER hardcode credentials directly in your source code. Use environment variables, configuration files, or a secrets management service (like Azure Key Vault or AWS Secrets Manager).
- Protect your service account JSON key file. Store it securely and do not commit it to version control. Treat it like a password. Add it to your
.gitignore
file. - Grant the least privilege necessary to your service account. Only give it the permissions required to access the Google Generative AI APIs.
Dependencies
- Google Generative AI SDK (C#) (This is a peer dependency.)
- Google.Apis.Auth
Contributing
Contributions are welcome! Please open an issue to discuss proposed changes or create a pull request.
License
MIT License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Google.Apis.Auth (>= 1.69.0)
- Google_GenerativeAI (>= 2.0.2)
-
.NETStandard 2.0
- Google.Apis.Auth (>= 1.69.0)
- Google_GenerativeAI (>= 2.0.2)
-
net5.0
- Google.Apis.Auth (>= 1.69.0)
- Google_GenerativeAI (>= 2.0.2)
-
net6.0
- Google.Apis.Auth (>= 1.69.0)
- Google_GenerativeAI (>= 2.0.2)
-
net7.0
- Google.Apis.Auth (>= 1.69.0)
- Google_GenerativeAI (>= 2.0.2)
-
net8.0
- Google.Apis.Auth (>= 1.69.0)
- Google_GenerativeAI (>= 2.0.2)
-
net9.0
- Google.Apis.Auth (>= 1.69.0)
- Google_GenerativeAI (>= 2.0.2)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Google_GenerativeAI.Auth:
Package | Downloads |
---|---|
Google_GenerativeAI.Web
This library is part of the Google_GenerativeAI SDK and provides .NET Web Application integration for seamless usage of the Google_GenerativeAI SDK. |
GitHub repositories
This package is not used by any popular GitHub repositories.