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
stringTarget Salesforce API version
httpClient
HttpClientCustom 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
clientId
stringThe Consumer Key from the connected app definition.
clientSecret
stringThe 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
stringSalesforce 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
token
stringThe refresh token the client application already received.
clientId
stringThe Consumer Key from the connected app definition.
clientSecret
stringThe 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
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
stringThe refresh token the client application already received.
clientId
stringThe Consumer Key from the connected app definition.
clientSecret
stringThe 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
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
stringClient ID, a.k.a. Consumer Key
clientSecret
stringClient Secret, a.k.a. Consumer Secret
username
stringUsername
password
stringPassword
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
stringClient ID, a.k.a. Consumer Key
clientSecret
stringClient Secret, a.k.a. Consumer Secret
username
stringUsername
password
stringPassword
tokenRequestEndpointUrl
stringToken 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
stringClient ID, a.k.a. Consumer Key
clientSecret
stringClient Secret, a.k.a. Consumer Secret
username
stringUsername
password
stringPassword
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
clientId
stringClient ID, a.k.a. Consumer Key
clientSecret
stringClient Secret, a.k.a. Consumer Secret
username
stringUsername
password
stringPassword
tokenRequestEndpointUrl
stringToken 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
clientId
stringThe Consumer Key from the connected app definition.
clientSecret
stringThe 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
stringThe Callback URL from the connected app definition.
code
stringAuthorization code the consumer must use to obtain the access and refresh tokens.
tokenRequestEndpointUrl
stringSalesforce token request endpoint