OfficeDev / Office-365-SDK-for-Android

Microsoft Services SDKs for Android produced by MS Open Tech.
https://dev.office.com/android
Other
224 stars 74 forks source link

Refresh token is failed and prompt is not allowed when using an AVD with API level lower than 18 #64

Closed ricalo closed 9 years ago

ricalo commented 9 years ago

I'm assuming I can use API level 14 or higher since that's what ADAL requires. Note that I'm using Office 365 SDK for Android v 0.11.1 If that is not true{ just let me know what API level is supported. Thank you! } else { Keep reading :bowtie: }

In my app I get the authentication page, I type credentials, everything goes fine. Then I try to get the services using discoveryClient.getServices().read() The app fails with error Refresh token is failed and prompt is not allowed. However, if I upgrade my AVD to API level 18 or higher the error goes away.

Here is the code that I'm using:

ListenableFuture<List<ServiceInfo>> services = discoveryClient
        .getservices().read();
Futures.addCallback(services,
        new FutureCallback<List<ServiceInfo>>() {
            @Override
            public void onSuccess(final List<ServiceInfo> result) {
                //Irrelevant, execution goes to the onFailure handler
            }

            @Override
            public void onFailure(final Throwable t) {
                Log.e("Asset", t.getMessage());
            }
        });

I also get this in logcat when using an AVD with API level lower than 18

DefaultTokenCacheStore﹕ ENCRYPTION_FAILED:Encryption failure ver:1.0.5
    java.lang.IllegalArgumentException: rawBytes
            at com.microsoft.aad.adal.StorageHelper.getSecretKey(StorageHelper.java:229)
            at com.microsoft.aad.adal.StorageHelper.loadSecretKeyForAPI(StorageHelper.java:174)
            at com.microsoft.aad.adal.StorageHelper.encrypt(StorageHelper.java:275)
            at com.microsoft.aad.adal.DefaultTokenCacheStore.encrypt(DefaultTokenCacheStore.java:104)
            at com.microsoft.aad.adal.DefaultTokenCacheStore.setItem(DefaultTokenCacheStore.java:179)
            at com.microsoft.aad.adal.AuthenticationContext.setItemToCacheForUser(AuthenticationContext.java:1431)
            at com.microsoft.aad.adal.AuthenticationContext.setItemToCache(AuthenticationContext.java:1404)
            at com.microsoft.aad.adal.AuthenticationContext.access$300(AuthenticationContext.java:53)
            at com.microsoft.aad.adal.AuthenticationContext$3.run(AuthenticationContext.java:800)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
            at java.util.concurrent.FutureTask.run(FutureTask.java:234)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
            at java.lang.Thread.run(Thread.java:856)
DefaultTokenCacheStore﹕ ENCRYPTION_FAILED:Encrypted output is null ver:1.0.5

Any ideas? Thank you!

marcote commented 9 years ago

Hey @Ricalo

My understanding is the following one: you can use ADAL with Android API level 14 but not as "out-of-the-box" as you do with API Level 18.

I will have to reach the ADAL guys on this matter, maybe we're missing a specific behavior or similar on lower APIs. You can try reaching them also, since we're just using ADAL as it were any other library.

Marcos

ricalo commented 9 years ago

Thank you, @marcote. I'll try reaching out to them too.

ricalo commented 9 years ago

I checked the ADAL samples and they use an utility to setup the encryption key if the SDK version is lower than 18. For more information, see

In my sample, I'm implementing such functionality in the AuthenticationController class.

marcote commented 9 years ago

Thank you @Ricalo . I will look for you sample and see if we can incorporate your code into our sample app to help other users with the similar concern.

Thanks again. Marcos

ricalo commented 9 years ago

It's going to get published pretty soon. I'll let you know as soon as it goes live.