pub enum AuthMode {
Password {
username: String,
password: Zeroizing<String>,
},
PrivateKey {
username: String,
private_key: Box<RsaPrivateKey>,
},
RefreshToken {
refresh_token: Zeroizing<String>,
},
}Expand description
Authentication mode for obtaining an OAuth Access Token from Salesforce.
Variants§
Password
Username + password authentication (OAuth password grant).
Requires client_secret to be set in the config.
Fields
PrivateKey
JWT Bearer Token Flow using RSA private key.
This is the recommended mode for server-to-server authentication.
Does NOT require client_secret. Each call generates a fresh JWT
assertion, so there is no OAuth Refresh Token to rotate.
See: https://help.salesforce.com/s/articleView?id=xcloud.remoteaccess_oauth_jwt_flow.htm
Fields
private_key: Box<RsaPrivateKey>RSA private key for signing JWT assertions
RefreshToken
OAuth Refresh Token grant.
Uses a long-lived OAuth Refresh Token to obtain short-lived OAuth
Access Tokens. Requires client_secret to be set in the config.
Important: The provider caches the OAuth Access Token and only refreshes it when genuinely expired, to avoid unnecessary OAuth Refresh Token rotation that would invalidate tokens held by other connections.
Implementations§
Source§impl AuthMode
impl AuthMode
Sourcepub fn password(
username: impl Into<String>,
password: impl Into<String>,
) -> Self
pub fn password( username: impl Into<String>, password: impl Into<String>, ) -> Self
Creates a password authentication mode.
Sourcepub fn private_key(
username: impl Into<String>,
private_key_pem: &str,
) -> SalesforceAuthResult<Self>
pub fn private_key( username: impl Into<String>, private_key_pem: &str, ) -> SalesforceAuthResult<Self>
Creates a private key authentication mode from a PEM-encoded private key.
§Arguments
username- Salesforce username (email) that authorized the connected appprivate_key_pem- RSA private key in PEM format (PKCS#8)
§Example
use hyperdb_api_salesforce::AuthMode;
let pem = "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----";
let mode = AuthMode::private_key("user@example.com", pem)?;§Errors
Returns SalesforceAuthError::PrivateKey if private_key_pem is
not a valid PKCS#8 PEM-encoded RSA private key (malformed PEM
envelope, wrong algorithm, or corrupted key bytes).
Sourcepub fn refresh_token(refresh_token: impl Into<String>) -> Self
pub fn refresh_token(refresh_token: impl Into<String>) -> Self
Creates an OAuth Refresh Token authentication mode.