Skip to main content

Crate busbar_sf_auth

Crate busbar_sf_auth 

Source
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.
FileTokenStorage
File-based token storage.
JwtAuth
JWT Bearer authentication for server-to-server integration.
OAuthClient
OAuth client for authenticating with Salesforce.
OAuthConfig
OAuth 2.0 configuration for a connected app.
SalesforceCredentials
Standard Salesforce credentials implementation.
TokenInfo
Token info from validation.
TokenResponse
Token response from OAuth.
WebFlowAuth
Web Server OAuth flow for web applications.

Enums§

ErrorKind
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.
TokenStorage
Trait for token storage implementations.

Type Aliases§

Result
Result type alias for sf-auth operations.