OneDrive / onedrive-sdk-android

OneDrive SDK for Android!
https://dev.onedrive.com
Other
148 stars 52 forks source link

DisambiguationAuthenticator is re-prompting for login information #61

Closed peternied closed 8 years ago

peternied commented 8 years ago

@1gravity @ThomasSHA

peternied commented 8 years ago

@1gravity @ThomasSHA could you try out this pull request and see if it resolved your problem?

ThomasSHA commented 8 years ago

Well, it does work... But I see some problems:

  1. It seems not to work with recent version of adal lib (1.1.16)
  2. SilentLogin still fails, so at least my workaround to get a "only try silent login"-functionality by overwriting the OneDriveClient will also still fail (code following)
 public IOneDriveClient loginSilentTry(final Activity activity) throws ClientAuthenticatorException {
            this.mClient.validate();
            this.mClient.getAuthenticator().init(this.mClient.getExecutors(), this.mClient.getHttpProvider(), activity, this.mClient.getLogger());
            IAccountInfo silentAccountInfo;
            try {
                silentAccountInfo = this.mClient.getAuthenticator().loginSilent();
            } catch (Exception var4) {
                throw new ClientAuthenticatorException("Unable to authenticate silently", var4, OneDriveErrorCodes.AuthenticationFailure);
            }

            if (silentAccountInfo != null) {
                return mClient;
            } else {
                throw new ClientAuthenticatorException("Unable to authenticate silently or interactively", OneDriveErrorCodes.AuthenticationFailure);
            }
        }

In my opinion it's a nice workaround, but not fixing the cause of the bug.

1gravity commented 8 years ago

It's working. Adding a silent login shouldn't be too hard either. E.g. by adding a loginAndBuildClient(final ICallback callback) to the OneDriveClient. The signature lacks the Activity parameter and so the method would try to login silently but then simply not do the interactive login call.

Here's a question. What is the adal library used for? I'm using OneDrive and OneDrive for Business with only the msa library so what's the point of having a separate adal lib?

peternied commented 8 years ago

I'm using OneDrive and OneDrive for Business

If you are using the DisambiguationAuthenicator you are using both a MSA library and ADAL library to authenticate. The ADAL library is the only way to authenticate AAD accounts with OneDrive for Business. There is a newly converged endpoint which can authenticate both with only a OAuth v2 flow but I had to modify existing libraries to get them to work

For silent login issue, I am still working with the ADAL team to get this resolved. You could use the default loginAndBuildClient(...) flow and whenever either the ADAL library is fixed, or I can work around the core problem you wouldn't have to alter your codepath.

ThomasSHA commented 8 years ago

One more thing: When I use the "loginAndBuildClient"-Login-Method -> login -> and then wait for an hour (until the token is no longer valid) inside the app and then try to do e.g. a list directory, it does not work. Like before the fix. You could tell me now, I should login again, or every hour, or every time I try to make a file operation, but I think that's now how it should work (please correct me if I'm wrong) :).

Following the code after the Token seems to be expired and I try to list of the root folder. (It seems like Token cannot be refreshed):

03-29 12:09:00.553 27475-29394/com.<PRIVATE>.onedrive D/DefaultExecutors[performOnBackground] - 67: Starting background task, current active count: 0
03-29 12:09:00.573 27475-3742/com.<PRIVATE>.onedrive D/AuthorizationInterceptor[intercept] - 71: Intercepting request, https://<PRIVATE><PRIVATE>-my.sharepoint.com/_api/v2.0/me/drive/root?expand=children
03-29 12:09:00.574 27475-3742/com.<PRIVATE>.onedrive D/AuthorizationInterceptor[intercept] - 82: Found account information
03-29 12:09:00.579 27475-3742/com.<PRIVATE>.onedrive V/TokenCacheItem: 2016-03-29 10:09:00-5ee7d0d8-ce32-42ea-bb09-476d4825a918-expiresOn:Tue Mar 29 11:27:27 GMT+02:00 2016 timeWithBuffer:Tue Mar 29 12:14:00 GMT+02:00 2016 Buffer:300 ver:1.1.7
03-29 12:09:00.585 27475-3742/com.<PRIVATE>.onedrive D/AuthorizationInterceptor[intercept] - 84: Account access token is expired, refreshing
03-29 12:09:00.587 27475-3742/com.<PRIVATE>.onedrive D/ADALAccountInfo[refresh] - 112: Refreshing access token...
03-29 12:09:00.587 27475-3742/com.<PRIVATE>.onedrive D/ADALAuthenticator[loginSilent] - 380: Starting login silent
03-29 12:09:00.588 27475-3742/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Sending async task from thread:3742 ver:1.1.7
03-29 12:09:00.590 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Running task in thread:27679 ver:1.1.7
03-29 12:09:00.595 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Token request started ver:1.1.7
03-29 12:09:00.601 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Checking refresh tokens ver:1.1.7
03-29 12:09:00.603 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Looking for regular refresh token ver:1.1.7
03-29 12:09:00.605 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Looking for Multi Resource Refresh token ver:1.1.7
03-29 12:09:00.607 27475-27679/com.<PRIVATE>.onedrive V/StorageHelper: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Starting decryption ver:1.1.7
03-29 12:09:00.613 27475-27679/com.<PRIVATE>.onedrive V/StorageHelper: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Finished decryption ver:1.1.7
03-29 12:09:00.616 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Refresh token is available and id:x/kcraqUBQSC27Gs7qUY8Kxe4Neni5ziKUrfeJGS4Uo= Key used:https://login.windows.net/common$null$<PRIVATE_CLIENT_ID>$y$1a4067c8-099e-4c54-8b1a-3893b2601219 ver:1.1.7
03-29 12:09:00.617 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Refresh token is available and it will attempt to refresh token ver:1.1.7
03-29 12:09:00.619 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Process refreshToken for Request authority:https://login.windows.net/common resource:https://<PRIVATE><PRIVATE>-my.sharepoint.com/_api/v2.0/me clientid:<PRIVATE_CLIENT_ID> refreshTokenId:x/kcraqUBQSC27Gs7qUY8Kxe4Neni5ziKUrfeJGS4Uo= ver:1.1.7
03-29 12:09:00.622 27475-27679/com.<PRIVATE>.onedrive V/WebRequestHandler: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-WebRequestHandler thread27679 ver:1.1.7
03-29 12:09:00.623 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-HttpWebRequest send thread:27679 ver:1.1.7
03-29 12:09:00.625 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-HttpWebRequest setupConnection thread:27679 ver:1.1.7
03-29 12:09:00.627 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Setting header: x-client-Ver ver:1.1.7
03-29 12:09:00.629 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Setting header: x-client-last-request ver:1.1.7
03-29 12:09:00.631 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Setting header: x-client-last-response-time ver:1.1.7
03-29 12:09:00.632 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Setting header: Host ver:1.1.7
03-29 12:09:00.633 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Setting header: x-client-last-endpoint ver:1.1.7
03-29 12:09:00.634 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Setting header: x-client-DM ver:1.1.7
03-29 12:09:00.636 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Setting header: x-client-OS ver:1.1.7
03-29 12:09:00.637 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Setting header: Accept ver:1.1.7
03-29 12:09:00.638 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Setting header: x-client-SKU ver:1.1.7
03-29 12:09:00.639 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Setting header: client-request-id ver:1.1.7
03-29 12:09:00.640 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:00-fba516de-83d5-4059-aa28-75d394093c3b-Setting header: x-ms-PKeyAuth ver:1.1.7
03-29 12:09:01.570 27475-27679/com.<PRIVATE>.onedrive E/HttpWebRequest: SERVER_ERROR:2016-03-29 10:09:01-fba516de-83d5-4059-aa28-75d394093c3b-IOException:https://login.windows.net/common/oauth2/token ver:1.1.7 
03-29 12:09:01.572 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:01-fba516de-83d5-4059-aa28-75d394093c3b-Status code:400 ver:1.1.7
03-29 12:09:01.577 27475-27679/com.<PRIVATE>.onedrive V/HttpWebRequest: 2016-03-29 10:09:01-fba516de-83d5-4059-aa28-75d394093c3b-Response is received ver:1.1.7
03-29 12:09:01.579 27475-27679/com.<PRIVATE>.onedrive V/Oauth: 2016-03-29 10:09:01-fba516de-83d5-4059-aa28-75d394093c3b-Token request does not have exception ver:1.1.7
                                                            Timestamp: 2016-03-29 10:09:06Z ver:1.1.7
03-29 12:09:01.583 27475-27679/com.<PRIVATE>.onedrive V/Oauth: 2016-03-29 10:09:01-3ce6244c-626c-4b39-9c27-ef0449a085ca-Response correlationId:3ce6244c-626c-4b39-9c27-ef0449a085ca ver:1.1.7
03-29 12:09:01.587 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:01-3ce6244c-626c-4b39-9c27-ef0449a085ca-Refresh token is not returned or empty ver:1.1.7
                                                                            Timestamp: 2016-03-29 10:09:06Z
03-29 12:09:01.592 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:01-3ce6244c-626c-4b39-9c27-ef0449a085ca-Remove refresh item from cache:https://login.windows.net/common$null$<PRIVATE_CLIENT_ID>$y$1a4067c8-099e-4c54-8b1a-3893b2601219 ver:1.1.7
03-29 12:09:01.593 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:01-3ce6244c-626c-4b39-9c27-ef0449a085ca-Token request started ver:1.1.7
03-29 12:09:01.597 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:01-3ce6244c-626c-4b39-9c27-ef0449a085ca-Checking refresh tokens ver:1.1.7
03-29 12:09:01.599 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:01-3ce6244c-626c-4b39-9c27-ef0449a085ca-Looking for regular refresh token ver:1.1.7
03-29 12:09:01.601 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:01-3ce6244c-626c-4b39-9c27-ef0449a085ca-Looking for Multi Resource Refresh token ver:1.1.7
03-29 12:09:01.603 27475-27679/com.<PRIVATE>.onedrive V/AuthenticationContext: 2016-03-29 10:09:01-3ce6244c-626c-4b39-9c27-ef0449a085ca-Refresh token is not available ver:1.1.7
03-29 12:09:01.606 27475-27679/com.<PRIVATE>.onedrive E/AuthenticationContext: AUTH_REFRESH_FAILED_PROMPT_NOT_ALLOWED:2016-03-29 10:09:01-3ce6244c-626c-4b39-9c27-ef0449a085ca-Prompt is not allowed and failed to get token: ver:1.1.7 
03-29 12:09:01.610 27475-27475/com.<PRIVATE>.onedrive D/ADALAuthenticator$3[onError] - 417: Silent authentication failure from ADAL; Code Refresh token is failed and prompt is not allowed
03-29 12:09:01.612 27475-3742/com.<PRIVATE>.onedrive E/DefaultHttpProvider[sendRequestInternal] - 303: Error during http request
                                                                                                    com.onedrive.sdk.core.ClientException: Error during http request
                                                                                                        at com.onedrive.sdk.http.DefaultHttpProvider.sendRequestInternal(DefaultHttpProvider.java:300)
                                                                                                        at com.onedrive.sdk.http.DefaultHttpProvider.access$000(DefaultHttpProvider.java:48)
                                                                                                        at com.onedrive.sdk.http.DefaultHttpProvider$1.run(DefaultHttpProvider.java:127)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                                        at java.lang.Thread.run(Thread.java:818)
                                                                                                     Caused by: com.onedrive.sdk.authentication.ClientAuthenticatorException: Silent authentication failure from ADAL; Code Refresh token is failed and prompt is not allowed
                                                                                                        at com.onedrive.sdk.authentication.ADALAuthenticator$3.onError(ADALAuthenticator.java:418)
                                                                                                        at com.microsoft.aad.adal.AuthenticationContext$CallbackHandler$1.run(AuthenticationContext.java:1034)
                                                                                                        at android.os.Handler.handleCallback(Handler.java:739)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                                        at android.os.Looper.loop(Looper.java:148)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                                                     Caused by: com.microsoft.aad.adal.AuthenticationException: Refresh token is failed and prompt is not allowed
                                                                                                        at com.microsoft.aad.adal.AuthenticationContext.localFlow(AuthenticationContext.java:1294)
                                                                                                        at com.microsoft.aad.adal.AuthenticationContext.acquireTokenAfterValidation(AuthenticationContext.java:1229)
                                                                                                        at com.microsoft.aad.adal.AuthenticationContext.acquireTokenLocalCall(AuthenticationContext.java:1123)
                                                                                                        at com.microsoft.aad.adal.AuthenticationContext.refreshToken(AuthenticationContext.java:1609)
                                                                                                        at com.microsoft.aad.adal.AuthenticationContext.localFlow(AuthenticationContext.java:1261)
                                                                                                        at com.microsoft.aad.adal.AuthenticationContext.acquireTokenAfterValidation(AuthenticationContext.java:1229)
                                                                                                        at com.microsoft.aad.adal.AuthenticationContext.acquireTokenLocalCall(AuthenticationContext.java:1123)
                                                                                                        at com.microsoft.aad.adal.AuthenticationContext.access$600(AuthenticationContext.java:58)
                                                                                                        at com.microsoft.aad.adal.AuthenticationContext$4.call(AuthenticationContext.java:1072)
                                                                                                        at com.microsoft.aad.adal.AuthenticationContext$4.call(AuthenticationContext.java:1067)
                                                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                                        at java.lang.Thread.run(Thread.java:818)
03-29 12:09:01.613 27475-3742/com.<PRIVATE>.onedrive D/DefaultExecutors[performOnForeground] - 125: Starting foreground task, current active count:0, with exception com.onedrive.sdk.core.ClientException: Error during http request
03-29 12:09:01.615 27475-27475/com.<PRIVATE>.onedrive E/MainActivity: listException 
                                                                   com.onedrive.sdk.core.ClientException: Error during http request
                                                                       at com.onedrive.sdk.http.DefaultHttpProvider.sendRequestInternal(DefaultHttpProvider.java:300)
                                                                       at com.onedrive.sdk.http.DefaultHttpProvider.access$000(DefaultHttpProvider.java:48)
                                                                       at com.onedrive.sdk.http.DefaultHttpProvider$1.run(DefaultHttpProvider.java:127)
                                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                       at java.lang.Thread.run(Thread.java:818)
                                                                    Caused by: com.onedrive.sdk.authentication.ClientAuthenticatorException: Silent authentication failure from ADAL; Code Refresh token is failed and prompt is not allowed
                                                                       at com.onedrive.sdk.authentication.ADALAuthenticator$3.onError(ADALAuthenticator.java:418)
                                                                       at com.microsoft.aad.adal.AuthenticationContext$CallbackHandler$1.run(AuthenticationContext.java:1034)
                                                                       at android.os.Handler.handleCallback(Handler.java:739)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                       at android.os.Looper.loop(Looper.java:148)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                    Caused by: com.microsoft.aad.adal.AuthenticationException: Refresh token is failed and prompt is not allowed
                                                                       at com.microsoft.aad.adal.AuthenticationContext.localFlow(AuthenticationContext.java:1294)
                                                                       at com.microsoft.aad.adal.AuthenticationContext.acquireTokenAfterValidation(AuthenticationContext.java:1229)
                                                                       at com.microsoft.aad.adal.AuthenticationContext.acquireTokenLocalCall(AuthenticationContext.java:1123)
                                                                       at com.microsoft.aad.adal.AuthenticationContext.refreshToken(AuthenticationContext.java:1609)
                                                                       at com.microsoft.aad.adal.AuthenticationContext.localFlow(AuthenticationContext.java:1261)
                                                                       at com.microsoft.aad.adal.AuthenticationContext.acquireTokenAfterValidation(AuthenticationContext.java:1229)
                                                                       at com.microsoft.aad.adal.AuthenticationContext.acquireTokenLocalCall(AuthenticationContext.java:1123)
                                                                       at com.microsoft.aad.adal.AuthenticationContext.access$600(AuthenticationContext.java:58)
                                                                       at com.microsoft.aad.adal.AuthenticationContext$4.call(AuthenticationContext.java:1072)
                                                                       at com.microsoft.aad.adal.AuthenticationContext$4.call(AuthenticationContext.java:1067)
                                                                       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                       at java.lang.Thread.run(Thread.java:818)
1gravity commented 8 years ago

Let me elaborate on my question about the ADAL library.

You build.gradle defines the dependencies like this:

dependencies {
    compile ('com.microsoft.services.msa:msa-auth:0.8.4') {
        exclude module: 'com.microsoft.services.msa'
    }
    compile ('com.microsoft.aad:adal:1.1.7') {
        exclude module: 'com.microsoft.aad'
    }
    compile ('com.google.code.gson:gson:2.3.1') {
        exclude module: 'com.google.code.gson'
    }
}

My guess is that you want to exclude the adal and msa libraries from the aar you're distributing which makes sense since not everyone would want both authentication methods. That's why your readme says to set up the dependencies like this:

dependency {
    compile 'com.onedrive.sdk:onedrive-sdk-android:1.1+'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.microsoft.services.msa:msa-auth:0.8.4'
    compile 'com.microsoft.aad:adal:1.1.11'
}

Unfortunately the excludes don't work and I get the following for the dependencies: +--- com.onedrive.sdk:onedrive-sdk-android:1.1.3 | +--- com.microsoft.aad:adal:1.1.7 | | --- com.android.support:support-v4:24.0.0-alpha1 | | --- LOCAL: internal_impl-24.0.0-alpha1.jar | --- com.microsoft.services.msa:msa-auth:0.8.4

That's the reason I don't have to add any dependencies in my gradle script except the one to the sdk of course and that's why I was confused why I need the adal at all (in fact it works "without" msa library too).

Now to make this correct, please use (instead of module:...):

exclude group: 'com.microsoft.services.msa'
exclude group: 'com.microsoft.aad'

This also makes sure the user can use the latest msa and adal libraries without running into dependency issues.

peternied commented 8 years ago

Just updated the pull request, turns out the bug was in the SDK code, the resource id != resource url, which is what the system was doing and that created the rest of the strange errors we saw.

Please check if this resolves your issue, and it should work immediately without a signout/signin

ThomasSHA commented 8 years ago

Now it seems to work like it should :dancers: Will test it inside the "real" app as soon as an aar is available!

Thanks for your help!

1gravity commented 8 years ago

My tests were mostly positive. There's however one more issue. Logging out of the ADAL authenticator doesn't work (it does for MSA). As a result I'm not able to switch between different OneDrive accounts (my app allows to select different cloud storage providers so they can use OneDrive, Dropbox or others). To test this I login to OneDrive for Business, then switch to e.g. Dropbox. My app logs out of OneDrive as soon as the user has authenticated with Dropbox. If I try to switch back to OneDrive, I would expect the disambiguation to kick in again which would allow me to pick another OneDrive account instead of the one I picked in the first place. Since the logout doesn't work, there's no disambiguation and I end of with the same acccount.

Here's the offending piece of code:

if (mMSAAuthenticator.getAccountInfo() != null) {
    mLogger.logDebug("Starting logout of MSA account");
    mMSAAuthenticator.logout();
} else if (mADALAuthenticator.getAccountInfo() != null) {
    mLogger.logDebug("Starting logout of ADAL account");
    mADALAuthenticator.logout();
}

What happens is that mMSAAuthenticator.getAccountInfo() is always !=null and the mADALAuthenticator.logout() is never executed. The session in the MSA authenticator is always initialized and so the getAccountInfo would always return an object even if it's really just an "empty shell":

{
/ /...
    this.session = new LiveConnectSession(this);
}

I guess what the code should be doing is something like this:

AccountType accountType = getAccountTypeInPreferences();
if (accountType == AccountType.MicrosoftAccount) {
    mLogger.logDebug("Starting logout of MSA account");
    mMSAAuthenticator.logout();
} else if (accountType == AccountType.ActiveDirectory) {
    mLogger.logDebug("Starting logout of ADAL account");
    mADALAuthenticator.logout();
}
ThomasSHA commented 8 years ago

updated the lib to 1.1.4 and it seems to work as expected!