Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit a005934

Browse files
author
Peter Nied
committed
Use AcquireToken to force refresh token to be saved in the cache
Fixes #36 When using the AquireTokenByRefreshToken(...) method, the underlying ADAL system does not guarentee the token will be saved for future use in the TokenCacheStore. Tracing into the AuthenticationContext implementation, refreshToken(..., final boolean useCache) is getting set to false in all of the 'refresh token` scenarios. Using aquireToken and then depending on the Prompt settings seems to be the best course of action to mitigate this issue. Note: it is not clear why this behavoir changed.
1 parent 2334579 commit a005934

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

onedrivesdk/src/main/java/com/onedrive/sdk/authentication/ADALAuthenticator.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public synchronized IAccountInfo login(final String emailAddressHint) throws Cli
295295

296296
// Request a fresh auth token for the OneDrive service.
297297
final AuthenticationResult oneDriveServiceAuthToken =
298-
getOneDriveServiceAuthResult(discoveryServiceAuthToken, oneDriveServiceInfo);
298+
getOneDriveServiceAuthResult(oneDriveServiceInfo);
299299

300300
// Get the OneDrive auth token and save a reference to it.
301301
final String serviceInfoAsString = mHttpProvider.getSerializer()
@@ -591,12 +591,10 @@ private ServiceInfo getOneDriveServiceInfoFromDiscoveryService(final String acce
591591

592592
/**
593593
* Gets the authentication token for the OneDrive service.
594-
* @param authenticationResult The authentication result from the Discovery Service.
595594
* @param oneDriveServiceInfo The OneDrive services info.
596595
* @return The authentication result for this OneDrive service.
597596
*/
598-
private AuthenticationResult getOneDriveServiceAuthResult(final AuthenticationResult authenticationResult,
599-
final ServiceInfo oneDriveServiceInfo) {
597+
private AuthenticationResult getOneDriveServiceAuthResult(final ServiceInfo oneDriveServiceInfo) {
600598
final SimpleWaiter authorityCallbackWaiter = new SimpleWaiter();
601599
final AtomicReference<ClientException> error = new AtomicReference<>();
602600
final AtomicReference<AuthenticationResult> oneDriveServiceAuthToken = new AtomicReference<>();
@@ -623,14 +621,13 @@ public void onError(final Exception e) {
623621
authorityCallbackWaiter.signal();
624622
}
625623
};
626-
final String refreshToken = authenticationResult.getRefreshToken();
627-
628624
mLogger.logDebug("Starting OneDrive resource refresh token request");
629-
mAdalContext.acquireTokenByRefreshToken(
630-
refreshToken,
631-
getClientId(),
632-
oneDriveServiceInfo.serviceResourceId,
633-
authorityCallback);
625+
mAdalContext.acquireToken(mActivity,
626+
oneDriveServiceInfo.serviceResourceId,
627+
getClientId(),
628+
getRedirectUrl(),
629+
PromptBehavior.Auto,
630+
authorityCallback);
634631

635632
mLogger.logDebug("Waiting for token refresh");
636633
authorityCallbackWaiter.waitForSignal();

0 commit comments

Comments
 (0)