Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/NetCoreForce.Client/AuthenticationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ public Task UsernamePasswordAsync(string clientId, string clientSecret, string u
/// <exception cref="ForceAuthException">Thrown if the authentication fails</exception>
public async Task UsernamePasswordAsync(string clientId, string clientSecret, string username, string password, string tokenRequestEndpointUrl)
{
await UsernamePasswordAsync(clientId, clientSecret, username, password, tokenRequestEndpointUrl,
response => JsonConvert.DeserializeObject<AccessTokenResponse>(response),
response => JsonConvert.DeserializeObject<AuthErrorResponse>(response));
}

/// <summary>
/// Authenticate using the "Username and Password" auth flow
/// </summary>
/// <param name="clientId">Client ID, a.k.a. Consumer Key</param>
/// <param name="clientSecret">Client Secret, a.k.a. Consumer Secret</param>
/// <param name="username">Username</param>
/// <param name="password">Password</param>
/// <param name="tokenRequestEndpointUrl">Token request endpoint URL, e.g. https://login.salesforce.com/services/oauth2/token</param>
/// <param name="DeserializeAccessToken">Function to deserialize the access token response</param>
/// <param name="DeserializeAuthError">Function to deserialize the auth error response</param>
/// <exception cref="ForceAuthException">Thrown if the authentication fails</exception>
public async Task UsernamePasswordAsync(string clientId, string clientSecret, string username, string password, string tokenRequestEndpointUrl, Func<string, AccessTokenResponse> DeserializeAccessToken, Func<string, AuthErrorResponse> DeserializeAuthError)
{
#if DEBUG
Stopwatch sw = new Stopwatch();
sw.Start();
Expand Down Expand Up @@ -153,7 +171,7 @@ public async Task UsernamePasswordAsync(string clientId, string clientSecret, st

if (responseMessage.IsSuccessStatusCode)
{
this.AccessInfo = JsonConvert.DeserializeObject<AccessTokenResponse>(response);
this.AccessInfo = DeserializeAccessToken(response);
}
else if (responseMessage.StatusCode == HttpStatusCode.NotFound)
{
Expand All @@ -162,7 +180,7 @@ public async Task UsernamePasswordAsync(string clientId, string clientSecret, st
}
else
{
var errorResponse = JsonConvert.DeserializeObject<AuthErrorResponse>(response);
var errorResponse = DeserializeAuthError(response);
throw new ForceAuthException(errorResponse.Error, errorResponse.ErrorDescription, responseMessage.StatusCode);
}
#if DEBUG
Expand Down