Skip to content

Instantly share code, notes, and snippets.

@wadewegner
Created February 5, 2014 20:12
Show Gist options
  • Save wadewegner/8832076 to your computer and use it in GitHub Desktop.
Save wadewegner/8832076 to your computer and use it in GitHub Desktop.
A simple demonstration of retry logic to simulate handling an invalid token and using the refresh token
_token.AccessToken = "GARBAGE"; // simulates the same behavior as expiration
var refreshToken = false;
do
{
if (refreshToken)
{
var auth = new AuthenticationClient();
await auth.TokenRefreshAsync(ConsumerKey, _token.RefreshToken);
_token.AccessToken = auth.AccessToken;
refreshToken = false;
}
try
{
var client = new ForceClient(_token.InstanceUrl, _token.AccessToken, _apiVersion);
var accounts = await client.QueryAsync<dynamic>("SELECT id, name, description FROM Account");
// do something with accounts
}
catch (ForceException ex)
{
if (ex.Message == "Session expired or invalid")
{
refreshToken = true;
}
}
} while (refreshToken);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment