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;
}
public void GetAccessTokenTest() { OAuthTokenCredential target = new OAuthTokenCredential(ClientID, ClientSecret); // TODO: Initialize to an appropriate value string expected = target.GetAccessToken(); string actual = target.GetAccessToken(); Assert.IsTrue(actual.ToLower().Contains("bearer")); }