diff --git a/README.md b/README.md index 3f39e66..4f4da57 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Integrate the [OneDrive API](https://dev.onedrive.com/README.htm) into your Andr ## 1. Installation ### 1.1 Install AAR via Gradle -Add the maven central repository to your projects build.gradle file then add a compile dependency for com.onedrive.sdk:onedrive-sdk-android:1.1.0 +Add the maven central repository to your projects build.gradle file then add a compile dependency for com.onedrive.sdk:onedrive-sdk-android:1.1.1 ```gradle repository { @@ -16,14 +16,14 @@ repository { dependency { // Include the sdk as a dependency - compile('com.onedrive.sdk:onedrive-sdk-android:1.1.0') + compile('com.onedrive.sdk:onedrive-sdk-android:1.1.1') // Include the gson dependency compile 'com.google.code.gson:gson:2.3.1' // Include supported authentication methods for your application compile 'com.microsoft.services.msa:msa-auth:0.8.4' - compile 'com.microsoft.aad:adal:1.1.7' + compile 'com.microsoft.aad:adal:1.1.11' } ``` diff --git a/gradle.properties b/gradle.properties index 26494fe..84fac6b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,5 +21,5 @@ org.gradle.jvmargs=-XX:MaxPermSize=512m mavenRepoUrl = https://api.bintray.com/maven/onedrive/Maven/onedrive-sdk-android mavenGroupId = com.onedrive.sdk mavenArtifactId = onedrive-sdk-android -mavenVersion = 1.1.0 +mavenVersion = 1.1.1 nightliesUrl = http://dl.bintray.com/onedrive/Maven diff --git a/onedrivesdk/src/main/java/com/onedrive/sdk/authentication/ADALAuthenticator.java b/onedrivesdk/src/main/java/com/onedrive/sdk/authentication/ADALAuthenticator.java index cd92078..1ebb996 100644 --- a/onedrivesdk/src/main/java/com/onedrive/sdk/authentication/ADALAuthenticator.java +++ b/onedrivesdk/src/main/java/com/onedrive/sdk/authentication/ADALAuthenticator.java @@ -31,6 +31,7 @@ import com.microsoft.aad.adal.AuthenticationCallback; import com.microsoft.aad.adal.AuthenticationCancelError; import com.microsoft.aad.adal.AuthenticationContext; +import com.microsoft.aad.adal.AuthenticationException; import com.microsoft.aad.adal.AuthenticationResult; import com.microsoft.aad.adal.PromptBehavior; import com.onedrive.sdk.core.ClientException; @@ -295,7 +296,7 @@ public synchronized IAccountInfo login(final String emailAddressHint) throws Cli // Request a fresh auth token for the OneDrive service. final AuthenticationResult oneDriveServiceAuthToken = - getOneDriveServiceAuthResult(discoveryServiceAuthToken, oneDriveServiceInfo); + getOneDriveServiceAuthResult(oneDriveServiceInfo); // Get the OneDrive auth token and save a reference to it. final String serviceInfoAsString = mHttpProvider.getSerializer() @@ -394,7 +395,13 @@ public void onSuccess(final AuthenticationResult authenticationResult) { @Override public void onError(final Exception e) { - error.set(new ClientAuthenticatorException("Silent authentication failure from ADAL", + String message = "Silent authentication failure from ADAL"; + if (e instanceof AuthenticationException) { + message = String.format("%s; Code %s", + message, + ((AuthenticationException)e).getCode().getDescription()); + } + error.set(new ClientAuthenticatorException(message, e, OneDriveErrorCodes.AuthenticationFailure)); loginSilentWaiter.signal(); @@ -509,7 +516,13 @@ public void onError(final Exception ex) { code = OneDriveErrorCodes.AuthenticationCancelled; } - final String message = "Error while retrieving the discovery service auth token"; + String message = "Error while retrieving the discovery service auth token"; + if (ex instanceof AuthenticationException) { + message = String.format("%s; Code %s", + message, + ((AuthenticationException)ex).getCode().getDescription()); + } + error.set(new ClientAuthenticatorException(message, ex, code)); mLogger.logError("Error while attempting to login interactively", error.get()); discoveryCallbackWaiter.signal(); @@ -591,12 +604,10 @@ private ServiceInfo getOneDriveServiceInfoFromDiscoveryService(final String acce /** * Gets the authentication token for the OneDrive service. - * @param authenticationResult The authentication result from the Discovery Service. * @param oneDriveServiceInfo The OneDrive services info. * @return The authentication result for this OneDrive service. */ - private AuthenticationResult getOneDriveServiceAuthResult(final AuthenticationResult authenticationResult, - final ServiceInfo oneDriveServiceInfo) { + private AuthenticationResult getOneDriveServiceAuthResult(final ServiceInfo oneDriveServiceInfo) { final SimpleWaiter authorityCallbackWaiter = new SimpleWaiter(); final AtomicReference error = new AtomicReference<>(); final AtomicReference oneDriveServiceAuthToken = new AtomicReference<>(); @@ -611,26 +622,31 @@ public void onSuccess(final AuthenticationResult authenticationResult) { @Override public void onError(final Exception e) { + String message = "Error while retrieving the service specific auth token"; OneDriveErrorCodes code = OneDriveErrorCodes.AuthenticationFailure; if (e instanceof AuthenticationCancelError) { code = OneDriveErrorCodes.AuthenticationCancelled; } + if (e instanceof AuthenticationException) { + message = String.format("%s; Code %s", + message, + ((AuthenticationException)e).getCode().getDescription()); + } - error.set(new ClientAuthenticatorException("Error while retrieving the service specific auth token", + error.set(new ClientAuthenticatorException(message, e, code)); mLogger.logError("Unable to refresh token into OneDrive service access token", error.get()); authorityCallbackWaiter.signal(); } }; - final String refreshToken = authenticationResult.getRefreshToken(); - mLogger.logDebug("Starting OneDrive resource refresh token request"); - mAdalContext.acquireTokenByRefreshToken( - refreshToken, - getClientId(), - oneDriveServiceInfo.serviceResourceId, - authorityCallback); + mAdalContext.acquireToken(mActivity, + oneDriveServiceInfo.serviceResourceId, + getClientId(), + getRedirectUrl(), + PromptBehavior.Auto, + authorityCallback); mLogger.logDebug("Waiting for token refresh"); authorityCallbackWaiter.waitForSignal();