microsoft-authentication-library-for-android: Android Emulator Authentication failed

I have faced really strange issue with authorization. For newly created emulator login finishes with success, but next logins are failing. I am reporting this issue just because using real device does not face such issue.

E/AuthenticationManager$a: Authentication failed
    com.microsoft.identity.client.MsalClientException: Auth failed with the error null
        at com.microsoft.identity.client.BaseRequest.performTokenRequest(BaseRequest.java:184)
        at com.microsoft.identity.client.BaseRequest$1.run(BaseRequest.java:111)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)
     Caused by: java.io.EOFException
        at com.android.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:95)
        at com.android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:179)
        at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:101)
        at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:628)
        at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:388)
        at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:332)
        at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:199)
        at com.android.okhttp.internal.http.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
        at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25)
        at com.microsoft.identity.client.HttpRequest.executeHttpSend(HttpRequest.java:191)
        at com.microsoft.identity.client.HttpRequest.sendWithRetry(HttpRequest.java:157)
        at com.microsoft.identity.client.HttpRequest.send(HttpRequest.java:138)
        at com.microsoft.identity.client.HttpRequest.sendPost(HttpRequest.java:114)
        at com.microsoft.identity.client.Oauth2Client.executeHttpRequest(Oauth2Client.java:142)
        at com.microsoft.identity.client.Oauth2Client.getToken(Oauth2Client.java:77)
        at com.microsoft.identity.client.BaseRequest.performTokenRequest(BaseRequest.java:180)
        at com.microsoft.identity.client.BaseRequest$1.run(BaseRequest.java:111) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
        at java.lang.Thread.run(Thread.java:818) 

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

I am pretty sure this is caused by: File: common/src/main/java/com/microsoft/identity/common/internal/net/HttpRequest.java (line ~212) Code: urlConnection.setRequestProperty("Connection", "close");

This code is executed in all recent releases of com.microsoft.identity:common up to the most recent release (as of this writing: v0.0.9). If I comment out this statement, I no longer get error unexpected end of stream on com.android.okhttp.Address while running MSAL in emulation.

Someone already commented out this code in :common branch ‘dev’: https://github.com/AzureAD/microsoft-authentication-library-common-for-android/commit/bd8d4b8607970c86af893598e04c1188f3a4c942 so I guess we’ll just wait to see if it gets merged into a release.

Strictly speaking this is probably not an :msal/:common bug, but rather an “okhttp in combination with Android emulation’s TCP/IP quirks” bug. However, if nobody knows of a good reason to set the (“Connection”, “close”) request header, then maybe remove it for the sake of developers working with MSAL in emulation. Besides, connection reuse is good on mobile!

Edit: Apologies to iambmelt. I missed their earlier comment where they mention the same line of code.