使用ADAL / OAuth2在Office365 Exchange Web服务上进行身份验证

时间:2018-08-07 08:54:14

标签: android oauth-2.0 exchangewebservices msal

我想通过Office365进行身份验证以使用Exchange Web服务。

我正在使用https://github.com/Azure-Samples/active-directory-android

中的Active Directory Android示例

我在Azure AD中注册了一个客户端,并在示例中输入了client_id,现在可以成功访问Graph API。

当我想访问EWS时,我将resource_id更改为https://outlook.office365.com/。 Web视图中的身份验证页面指的是我的应用程序名称,我被要求授予我的应用程序访问邮箱等(长列表)的权限,但是当我接受时,我没有获得授权令牌。 抛出IOException,并且示例崩溃,因为onError中的异常为null。 这是控制台输出:

Webview starts loading.  ver:1.14.1 null
DisplaySpinner:true showing:true ver:1.14.1 null
Navigation is detected ver:1.14.1 null
Navigation starts with the redirect uri. ver:1.14.1 null
It is not a broker request ver:1.14.1 null
Return To Caller:2003 ver:1.14.1 null
DisplaySpinner:false showing:true ver:1.14.1 null    
Set request id related to response. REQUEST_ID for caller returned to:84329944 ver:1.14.1 null
AuthenticationActivity onPause unregister receiver ver:1.14.1 null
Spinner at onPause will dismiss ver:1.14.1 null
Get waiting request. requestId:84329944 ver:1.14.1 null
Waiting request found. RequestId:84329944 ver:1.14.1 null
Start token acquisition with auth code. ver:1.14.1 null
Building request message for redeeming token with auth code. ver:1.14.1 null
Sending request to redeem token with auth code. ver:1.14.1 null
WebRequestHandler thread3642 ver:1.14.1 null
HttpWebRequest send.  ver:1.14.1 null
HttpWebRequest setupConnection. ver:1.14.1 null
Setting header.  ver:1.14.1 null
Setting header.  ver:1.14.1 null
Setting header.  ver:1.14.1 null
Setting header.  ver:1.14.1 null
IOException is thrown when sending the request.  ver:1.14.1 null
Server returned an error ver:1.14.1 java.io.IOException: unexpected end of stream on com.android.okhttp.Address@6de7d5e0
        at com.android.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:201)
        at com.android.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127)
        at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:737)
        at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:609)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:471)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:244)
        at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
        at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(Unknown Source:0)
        at com.microsoft.aad.adal.HttpWebRequest.send(HttpWebRequest.java:132)
        at com.microsoft.aad.adal.WebRequestHandler.sendPost(WebRequestHandler.java:76)
        at com.microsoft.aad.adal.Oauth2.postMessage(Oauth2.java:494)
        at com.microsoft.aad.adal.Oauth2.getTokenForCode(Oauth2.java:473)
        at com.microsoft.aad.adal.Oauth2.getToken(Oauth2.java:424)
        at com.microsoft.aad.adal.AcquireTokenInteractiveRequest.acquireTokenWithAuthCode(AcquireTokenInteractiveRequest.java:98)
        at com.microsoft.aad.adal.AcquireTokenRequest$3.run(AcquireTokenRequest.java:790)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.io.EOFException: \n not found: size=0 content=...
        at com.android.okhttp.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:200)
        at com.android.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:186)
        at com.android.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:127) 
        at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:737) 
        at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:609) 
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:471) 
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:407) 
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:244) 
        at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210) 
        at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(Unknown Source:0) 
        at com.microsoft.aad.adal.HttpWebRequest.send(HttpWebRequest.java:132) 
        at com.microsoft.aad.adal.WebRequestHandler.sendPost(WebRequestHandler.java:76) 
        at com.microsoft.aad.adal.Oauth2.postMessage(Oauth2.java:494) 
        at com.microsoft.aad.adal.Oauth2.getTokenForCode(Oauth2.java:473) 
        at com.microsoft.aad.adal.Oauth2.getToken(Oauth2.java:424) 
        at com.microsoft.aad.adal.AcquireTokenInteractiveRequest.acquireTokenWithAuthCode(AcquireTokenInteractiveRequest.java:98) 
        at com.microsoft.aad.adal.AcquireTokenRequest$3.run(AcquireTokenRequest.java:790) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) 
        at java.lang.Thread.run(Thread.java:764) 
Authorization code not exchanged for token ver:1.14.1 null
Sending error to callback CorrelationId: f5682c66-7842-434a-b738-1820bab73d0b ver:1.14.1 null
08-07 09:29:28.457 3095-3642/com.azuresamples.azureadsampleapp.azureadsampleapp D/MainActivity: Microsoft.ADAL.request_id: 59be3f1b-c94c-49e3-81f9-67e452f86f9c
Microsoft.ADAL.is_frt: 
Microsoft.ADAL.device_id: rBrLDMJwqslyGQ0K3jDfgZkbGl0+QhuL6XpXzf5rLwg=
Microsoft.ADAL.cache_event_count: 4
Microsoft.ADAL.api_id: 108
Microsoft.ADAL.authority_type: aad
Microsoft.ADAL.application_name: com.azuresamples.azureadsampleapp.azureadsampleapp
Microsoft.ADAL.application_version: 1.0
Microsoft.ADAL.authority_validation_status: not_done
08-07 09:29:28.458 3095-3642/com.azuresamples.azureadsampleapp.azureadsampleapp D/MainActivity: Microsoft.ADAL.response_time: 54642
Microsoft.ADAL.is_mrrt: 
Microsoft.ADAL.is_rt: 
Microsoft.ADAL.client_id: b3a48f5c-4516-4cf1-bb01-8c840ea51545
Microsoft.ADAL.is_successful: false
Microsoft.ADAL.correlation_id: f5682c66-7842-434a-b738-1820bab73d0b
Microsoft.ADAL.prompt_behavior: Auto
Microsoft.ADAL.ui_event_count: 1

我在做什么错了?

0 个答案:

没有答案