CertiForce 0.0.10
dotnet add package CertiForce --version 0.0.10
NuGet\Install-Package CertiForce -Version 0.0.10
<PackageReference Include="CertiForce" Version="0.0.10" />
<PackageVersion Include="CertiForce" Version="0.0.10" />
<PackageReference Include="CertiForce" />
paket add CertiForce --version 0.0.10
#r "nuget: CertiForce, 0.0.10"
#addin nuget:?package=CertiForce&version=0.0.10
#tool nuget:?package=CertiForce&version=0.0.10
CertiForce
A .NET library for secure Salesforce authentication using JWT Bearer Token Flow with private key authentication. This library provides a more secure alternative to username/password authentication by leveraging X.509 certificates for server-to-server authentication.
Features
- Secure Salesforce authentication using JWT Bearer Token Flow
- Support for PKCS#1 and PKCS#8 private key formats
- Async/await support for all operations
- Extensible architecture with interfaces for custom implementations
- Built with .NET 8.0
Installation
NuGet Package Manager
Install-Package CertiForce -Version 0.0.18
.NET CLI
dotnet add package CertiForce --version 0.0.18
Prerequisites
- .NET 8.0 SDK or later
- A Salesforce Connected App with JWT Bearer Flow enabled
- A valid X.509 certificate with private key (PKCS#1 or PKCS#8 format)
- Salesforce User with the necessary permissions
Usage
Basic Usage
using CertUtils;
using CertUtils.Cert;
using CertUtils.Salesforce;
using CertUtils.Token;
// Initialize the providers
var privateKeyProvider = new UrlPrivateKeyProvider("https://your-domain.com/private.key");
var jwtTokenGenerator = new JwtTokenGenerator(
"your-client-id",
"your-salesforce-username",
"https://login.salesforce.com"
);
var tokenRequester = new SalesforceTokenRequester("https://login.salesforce.com");
// Create the token provider
var tokenProvider = new SalesforceTokenProvider(
privateKeyProvider,
jwtTokenGenerator,
tokenRequester
);
// Get the access token
try
{
string accessToken = await tokenProvider.GetAccessTokenAsync();
Console.WriteLine($"Access Token: {accessToken}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Custom Implementations
You can implement the following interfaces to customize the behavior:
IPrivateKeyProvider
: Provide private key from custom sourcesIJwtTokenGenerator
: Custom JWT token generationITokenRequester
: Custom token request handling
Configuration
Salesforce Connected App Setup
- In Salesforce Setup, navigate to App Manager
- Create a new Connected App
- Enable Use digital signatures and upload your certificate
- Enable JWT Bearer Flow
- Add the following OAuth scopes:
- Access and manage your data (api)
- Perform requests on your behalf at any time (refresh_token, offline_access)
Error Handling
The library throws exceptions for various error conditions. Always wrap token acquisition in try-catch blocks and handle exceptions appropriately.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Acknowledgments
- Built with ❤️ by Richard Lawidjaja
- Uses Portable.BouncyCastle for cryptographic operations
- Inspired by Salesforce's JWT Bearer Token Flow
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
- Portable.BouncyCastle (>= 1.9.0)
- System.IdentityModel.Tokens.Jwt (>= 8.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.