Overview
TheSalesforceCredentials struct encapsulates the OAuth 2.0 credentials needed to authenticate with Salesforce. This includes client credentials and user credentials for password-based OAuth flow.
Definition
Properties
OAuth client ID issued by Salesforce for your OAuth application. This identifies your application to Salesforce during authentication.
OAuth client secret issued by Salesforce for your OAuth application. This should be kept secure and never exposed in client-side code.
Salesforce username for the user account that will be used for API authentication. This should be a dedicated service account when possible.
Salesforce password for the user account. This should meet Salesforce security requirements and be stored securely.
Initializer
SalesforceCredentials instance with the provided OAuth and user credentials.
Usage Example
Security Best Practices
Credential Storage
- Environment Variables: Store credentials in environment variables
- Secure Keychain: Use iOS/macOS keychain for mobile apps
- Encrypted Storage: Encrypt credentials in persistent storage
- No Hardcoding: Never hardcode credentials in source code
OAuth Configuration
- Minimal Scopes: Request only necessary OAuth scopes
- Client Security: Keep client secrets secure and rotate regularly
- User Permissions: Use dedicated service account when possible
- Network Security: Always use HTTPS for credential transmission
Integration Patterns
Environment-Based Configuration
Keychain Integration (iOS/macOS)
Validation
- Required Fields: All fields are required for valid authentication
- Format Validation: Client ID and username should be non-empty strings
- Password Security: Password should meet Salesforce security requirements
- Client Validation: Client ID and secret should be valid OAuth credentials
