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
apiVersionstringTarget Salesforce API version
httpClientHttpClientCustom HttpClient (Optional)
Properties
AccessInfo
The access token response from a successful authentication.
public AccessTokenResponse AccessInfo { get; }
Property Value
ApiVersion
public string ApiVersion { get; set; }
Property Value
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
clientIdstringThe Consumer Key from the connected app definition.
clientSecretstringThe 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.
tokenRequestEndpointUrlstringSalesforce token request endpoint
Returns
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
tokenstringThe refresh token the client application already received.
clientIdstringThe Consumer Key from the connected app definition.
clientSecretstringThe 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.
introspectTokenEndpointUrlstring
Returns
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
refreshTokenstringThe refresh token the client application already received.
clientIdstringThe Consumer Key from the connected app definition.
clientSecretstringThe 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.
tokenRequestEndpointUrlstring
Returns
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
clientIdstringClient ID, a.k.a. Consumer Key
clientSecretstringClient Secret, a.k.a. Consumer Secret
usernamestringUsername
passwordstringPassword
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
clientIdstringClient ID, a.k.a. Consumer Key
clientSecretstringClient Secret, a.k.a. Consumer Secret
usernamestringUsername
passwordstringPassword
tokenRequestEndpointUrlstringToken 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
clientIdstringClient ID, a.k.a. Consumer Key
clientSecretstringClient Secret, a.k.a. Consumer Secret
usernamestringUsername
passwordstringPassword
Returns
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
clientIdstringClient ID, a.k.a. Consumer Key
clientSecretstringClient Secret, a.k.a. Consumer Secret
usernamestringUsername
passwordstringPassword
tokenRequestEndpointUrlstringToken request endpoint URL, e.g. https://login.salesforce.com/services/oauth2/token
Returns
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
clientIdstringThe Consumer Key from the connected app definition.
clientSecretstringThe 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.
redirectUristringThe Callback URL from the connected app definition.
codestringAuthorization code the consumer must use to obtain the access and refresh tokens.
tokenRequestEndpointUrlstringSalesforce token request endpoint