Table of Contents

Class AuthenticationClient

Namespace
NetCoreForce.Client
Assembly
NetCoreForce.Client.dll
public class AuthenticationClient : IDisposable
Inheritance
AuthenticationClient
Implements
Inherited Members

Constructors

AuthenticationClient()

Initialize the AuthenticationClient with the libary's default Salesforce API version, and default HttpClient

See the DefaultApiVersion property

public AuthenticationClient()

AuthenticationClient(string, HttpClient)

Initialize the AuthenticationClient with the specified Salesforce API version and/or HttpClient

public AuthenticationClient(string apiVersion = null, HttpClient httpClient = null)

Parameters

apiVersion string

Target Salesforce API version

httpClient HttpClient

Custom HttpClient (Optional)

Properties

AccessInfo

The access token response from a successful authentication.

public AccessTokenResponse AccessInfo { get; }

Property Value

AccessTokenResponse

AccessTokenResponse

ApiVersion

public string ApiVersion { get; set; }

Property Value

string

Methods

ClientCredentialsAsync(string, string, string)

Client credentials OAuth Authentication Flow

https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_client_credentials_flow.htm

public Task ClientCredentialsAsync(string clientId, string clientSecret, string tokenRequestEndpointUrl = "https://login.salesforce.com/services/oauth2/token")

Parameters

clientId string

The Consumer Key from the connected app definition.

clientSecret string

The Consumer Secret from the connected app definition. Required unless the Require Secret for Web Server Flow setting is not enabled in the connected app definition.

tokenRequestEndpointUrl string

Salesforce token request endpoint

Returns

Task

AccessTokenResponse

Dispose()

public void Dispose()

IntrospectTokenAsync(string, string, string, string)

Introspect a access token

public Task<IntrospectTokenResponse> IntrospectTokenAsync(string token, string clientId, string clientSecret = "", string introspectTokenEndpointUrl = "https://login.salesforce.com/services/oauth2/introspect")

Parameters

token string

The refresh token the client application already received.

clientId string

The Consumer Key from the connected app definition.

clientSecret string

The Consumer Secret from the connected app definition. Required unless the Require Secret for Web Server Flow setting is not enabled in the connected app definition.

introspectTokenEndpointUrl string

Returns

Task<IntrospectTokenResponse>

TokenRefreshAsync(string, string, string, string)

Obtain a new access token using a refresh token

public Task TokenRefreshAsync(string refreshToken, string clientId, string clientSecret = "", string tokenRequestEndpointUrl = "https://login.salesforce.com/services/oauth2/token")

Parameters

refreshToken string

The refresh token the client application already received.

clientId string

The Consumer Key from the connected app definition.

clientSecret string

The Consumer Secret from the connected app definition. Required unless the Require Secret for Web Server Flow setting is not enabled in the connected app definition.

tokenRequestEndpointUrl string

Returns

Task

UsernamePassword(string, string, string, string)

Authenticate using the "Username and Password" auth flow, synchronously

Uses a default Token request endpoint URL: https://login.salesforce.com/services/oauth2/token

public void UsernamePassword(string clientId, string clientSecret, string username, string password)

Parameters

clientId string

Client ID, a.k.a. Consumer Key

clientSecret string

Client Secret, a.k.a. Consumer Secret

username string

Username

password string

Password

Exceptions

ForceAuthException

Thrown if the authentication fails

UsernamePassword(string, string, string, string, string)

Authenticate using the "Username and Password" auth flow, synchronously

Uses a default Token request endpoint URL: https://login.salesforce.com/services/oauth2/token

public void UsernamePassword(string clientId, string clientSecret, string username, string password, string tokenRequestEndpointUrl)

Parameters

clientId string

Client ID, a.k.a. Consumer Key

clientSecret string

Client Secret, a.k.a. Consumer Secret

username string

Username

password string

Password

tokenRequestEndpointUrl string

Token request endpoint URL, e.g. https://login.salesforce.com/services/oauth2/token

Exceptions

ForceAuthException

Thrown if the authentication fails

UsernamePasswordAsync(string, string, string, string)

Authenticate using the "Username and Password" auth flow

Uses a default Token request endpoint URL: https://login.salesforce.com/services/oauth2/token

public Task UsernamePasswordAsync(string clientId, string clientSecret, string username, string password)

Parameters

clientId string

Client ID, a.k.a. Consumer Key

clientSecret string

Client Secret, a.k.a. Consumer Secret

username string

Username

password string

Password

Returns

Task

Exceptions

ForceAuthException

Thrown if the authentication fails

UsernamePasswordAsync(string, string, string, string, string)

Authenticate using the "Username and Password" auth flow

public Task UsernamePasswordAsync(string clientId, string clientSecret, string username, string password, string tokenRequestEndpointUrl)

Parameters

clientId string

Client ID, a.k.a. Consumer Key

clientSecret string

Client Secret, a.k.a. Consumer Secret

username string

Username

password string

Password

tokenRequestEndpointUrl string

Token request endpoint URL, e.g. https://login.salesforce.com/services/oauth2/token

Returns

Task

Exceptions

ForceAuthException

Thrown if the authentication fails

WebServerAsync(string, string, string, string, string)

Web Server OAuth Authentication Flow

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_web_server_oauth_flow.htm

public Task WebServerAsync(string clientId, string clientSecret, string redirectUri, string code, string tokenRequestEndpointUrl = "https://login.salesforce.com/services/oauth2/token")

Parameters

clientId string

The Consumer Key from the connected app definition.

clientSecret string

The Consumer Secret from the connected app definition. Required unless the Require Secret for Web Server Flow setting is not enabled in the connected app definition.

redirectUri string

The Callback URL from the connected app definition.

code string

Authorization code the consumer must use to obtain the access and refresh tokens.

tokenRequestEndpointUrl string

Salesforce token request endpoint

Returns

Task

AccessTokenResponse