SfLoginLib is a small .NET library with one job: log in to Salesforce and return a session ID you can reuse for REST API calls.
- Reads the highest available Salesforce REST API version from
/services/data/ - Performs a Salesforce SOAP login using:
- username
- password
- security token (appended to password for login)
- instance URL
- Verifies the returned session ID works against the REST API
If the highest REST version does not support SOAP login for the org yet, the library automatically falls back to the highest SOAP-supported version for login, while still using the highest REST version for subsequent REST API calls.
The Salesforce security token is used during login (appended to the password in the SOAP login request).
The session ID returned by this library is the value you normally use in:
Authorization: Bearer {sessionId}
using SfLoginLib;
var credentials = new SalesforceLoginCredentials(
Username: "user@example.com",
Password: "your-password",
SecurityToken: "your-security-token",
InstanceUri: new Uri("https://your-domain.lightning.force.com"));
using var loginClient = new SalesforceLoginClient();
SalesforceLoginResult result = await loginClient.LoginAsync(credentials);
Console.WriteLine(result.SessionId);
Console.WriteLine(result.ApiVersion);
Console.WriteLine(result.SoapLoginApiVersion);
Console.WriteLine(result.RestApiBaseUri);The integration tests are in tests/SfLoginLib.IntegrationTests and do not store credentials in source control. They read from environment variables:
SFLOGIN_USERNAMESFLOGIN_PASSWORDSFLOGIN_SECURITY_TOKENSFLOGIN_INSTANCE_URL
Optional:
RUN_SF_INTEGRATION_TESTS=true(fail fast if credentials are missing instead of skipping)
Example:
export SFLOGIN_USERNAME="..."
export SFLOGIN_PASSWORD="..."
export SFLOGIN_SECURITY_TOKEN="..."
export SFLOGIN_INSTANCE_URL="https://your-domain.lightning.force.com"
dotnet test tests/SfLoginLib.IntegrationTests/SfLoginLib.IntegrationTests.csproj