Created
February 5, 2014 20:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_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