/// <summary>
/// Returns the currently cached access token. If no access token was
/// previously cached, or if the current access token is expired, then
/// a new one is generated and returned.
/// </summary>
/// <returns>The OAuth access token to use for making PayPal requests.</returns>
/// <exception cref="PayPal.Exception.MissingCredentialException">Thrown if clientId or clientSecret are null or empty.</exception>
/// <exception cref="PayPal.Exception.InvalidCredentialException">Thrown if there is an issue converting the credentials to a formatted authorization string.</exception>
/// <exception cref="PayPal.Exception.IdentityException">Thrown if authorization fails as a result of providing invalid credentials.</exception>
/// <exception cref="PayPal.Exception.HttpException">Thrown if authorization fails and an HTTP error response is received.</exception>
/// <exception cref="PayPal.Exception.ConnectionException">Thrown if there is an issue attempting to connect to PayPal's services.</exception>
/// <exception cref="PayPal.Exception.ConfigException">Thrown if there is an error with any informaiton provided by the <see cref="PayPal.Manager.ConfigManager"/>.</exception>
/// <exception cref="PayPal.Exception.PayPalException">Thrown for any other general exception. See inner exception for further details.</exception>
public string GetAccessToken()
{
// If the cached access token value is valid, then check to see if
// it has expired.
if (!string.IsNullOrEmpty(this.accessToken))
{
// If the time since the access token was created is greater
// than the access token's specified expiration time less the
// safety gap, then regenerate the token.
double elapsedSeconds = (DateTime.Now - this.AccessTokenLastCreationDate).TotalSeconds;
if (elapsedSeconds > this.AccessTokenExpirationInSeconds - this.AccessTokenExpirationSafetyGapInSeconds)
{
this.accessToken = null;
}
}
// If the cached access token is empty or null, then generate a new token.
if (string.IsNullOrEmpty(this.accessToken))
{
// Write Logic for passing in Detail to Identity Api Serv and
// computing the token
// Set the Value inside the accessToken and result
string base64ClientId = OAuthTokenCredential.ConvertClientCredentialsToBase64String(this.ClientId, this.ClientSecret);
this.accessToken = this.GenerateOAuthToken(base64ClientId);
}
return(this.accessToken);
}