Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Credentials concerns #23

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 13 additions & 0 deletions src/main/java/com/gettyimages/api/Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,22 @@ public static Credentials GetInstance(String apiKey, String apiSecret, String us
}

public Token GetAccessToken() throws SdkException {

// "now" seems like a bad name. The value is set to some time into the future to then
// compare to the token expiration. If the token expiration is equal to or after this
// time then we keep caching.
Calendar now = Calendar.getInstance();
now.add(Calendar.MINUTE, 5);

// Bug? This reads to me like we'll never cache the token.
// It only returns the cached token if the CredentialType is all at once NOT:
// - ClientCredentials
// - ResourceOwner
// - RefreshToken
// First, this doesn't seem right: you'd want to cache the token in the case of CC or RO, right?
// Second, we don't offer any way to instantiate Credentials *except* for these cases.
// That tells me we're never caching the token.
// Keep caching as long as the token's expiration is equal to or after 5 minutes from now
if (CredentialType != CredentialType.ClientCredentials && CredentialType != CredentialType.ResourceOwner && CredentialType != CredentialType.RefreshToken
||
(accessToken != null && accessToken.getExpiration().compareTo(now.getTime()) >= 0)) {
Expand Down