Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SfLoginLib

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.

What it does

  1. Reads the highest available Salesforce REST API version from /services/data/
  2. Performs a Salesforce SOAP login using:
    • username
    • password
    • security token (appended to password for login)
    • instance URL
  3. 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.

Important note about tokens

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}

Usage

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);

Integration tests (safe setup)

The integration tests are in tests/SfLoginLib.IntegrationTests and do not store credentials in source control. They read from environment variables:

  • SFLOGIN_USERNAME
  • SFLOGIN_PASSWORD
  • SFLOGIN_SECURITY_TOKEN
  • SFLOGIN_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

About

A simple library to login into Salesforce's REST API

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages