Expand description
§sf-auth
Salesforce authentication library supporting secure OAuth 2.0 flows.
§Security
This library is designed with security in mind:
- Sensitive data (tokens, secrets) are redacted in Debug output
- Tracing/logging skips credential parameters
- Error messages sanitize any credential data
- Device Code Flow excluded (deprecated for security reasons)
§Supported Authentication Methods
- OAuth 2.0 Web Server Flow - For web applications with user interaction
- OAuth 2.0 JWT Bearer Flow - For server-to-server integration
- OAuth 2.0 Refresh Token - For refreshing expired access tokens
§Example
ⓘ
use sf_auth::{Credentials, SalesforceCredentials, JwtAuth};
#[tokio::main]
async fn main() -> Result<(), sf_auth::Error> {
// From environment variables
let creds = SalesforceCredentials::from_env()?;
// From SFDX CLI
let creds = SalesforceCredentials::from_sfdx_alias("myorg").await?;
// JWT Bearer Flow (server-to-server)
let private_key = std::fs::read("path/to/key.pem")?;
let jwt_auth = JwtAuth::new("consumer_key", "username", private_key);
let token = jwt_auth.authenticate("https://login.salesforce.com").await?;
Ok(())
}Structs§
- Error
- Error type for sf-auth operations.
- File
Token Storage - File-based token storage.
- JwtAuth
- JWT Bearer authentication for server-to-server integration.
- OAuth
Client - OAuth client for authenticating with Salesforce.
- OAuth
Config - OAuth 2.0 configuration for a connected app.
- Salesforce
Credentials - Standard Salesforce credentials implementation.
- Token
Info - Token info from validation.
- Token
Response - Token response from OAuth.
- WebFlow
Auth - Web Server OAuth flow for web applications.
Enums§
- Error
Kind - The kind of error that occurred.
Constants§
- PRODUCTION_
LOGIN_ URL - Default Salesforce login URL for production.
- SANDBOX_
LOGIN_ URL - Default Salesforce login URL for sandbox.
Traits§
- Credentials
- Trait for Salesforce credentials.
- Token
Storage - Trait for token storage implementations.
Type Aliases§
- Result
- Result type alias for sf-auth operations.