我有一些从WPF客户端调用的Azure托管移动应用程序的身份验证代码。它尝试在初始化包含身份验证服务的Prism模块的过程中对用户进行身份验证。要进行身份验证的异步方法编写如下:
public async Task AcquireTokenAndAuthenticateWebApiAsync()
{
try
{
//todo these are hardcoded :-( ... need to come from app settings!!
// settings for authentication
string resourceId = "https://windinspectordevmobileappservice.azurewebsites.net";
//string resourceId = "http://localhost:51293/";
string clientId = "5fe3b968-1d23-4667-9c31-86fac4ab4aec";
Uri redirectUri = new Uri("https://windinspectordevmobileappservice.azurewebsites.net/.auth/login/done"); // Page to say you have sucessfully signed in
const string appServiceUrl = "https://windinspectordevmobileappservice.azurewebsites.net";
string authorityUri = "https://login.windows.net/dnv.onmicrosoft.com";
this.authContext = new AuthenticationContext(authorityUri);
// authenticate against the AD
var result = await authContext.AcquireTokenAsync(
resourceId, clientId, redirectUri,
new PlatformParameters(PromptBehavior.Auto, false));
this.authResult = result;
// authenticate against the web api
Client = new MobileServiceClient(appServiceUrl);
JObject payload = new JObject();
payload["access_token"] = authResult.AccessToken;
var user = await Client.LoginAsync(
MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory,
payload).ConfigureAwait(false);
this.authenticatedUserName = this.authResult.UserInfo.DisplayableId;
}
catch (InvalidOperationException e)
{
}
}
大约50%的时间对LoginAsync的调用成功。但是,在其他时候,LoginAsync调用只是超时(任务超时,异常)。什么可能导致这个?
我试图打开客户端中的日志,但没有看到日志中超时的原因:
成功LoginAsync呼叫的应用程序日志:
2017-01-27T16:24:29 PID[23292] Verbose Received request: POST https://windinspectordevmobileappservice.azurewebsites.net/.auth/login/aad
2017-01-27T16:24:29 PID[23292] Verbose JWT validation succeeded. Subject: '__HeuajpWfXmUxZBrDvwAqcV0UOirMVrs5iCwvpnrrY', Issuer: 'https://sts.windows.net/adf10e2b-b6e9-41d6-be2f-c12bb566019c/'.
2017-01-27T16:24:29 PID[23292] Information Login completed for 'max.palmer@dnvgl.com'. Provider: 'aad'.
2017-01-27T16:24:29 PID[23292] Information Sending response: 200.77 OK
2017-01-27 16:24:29 WINDINSPECTORDEVMOBILEAPPSERVICE POST /.auth/login/aad X-ARR-LOG-ID=4f08
来自LoginAsync的应用程序日志调用超时:
734a-75e2-4674-a9c8-bd74caa1aa3f 443 - 80.5.95.115 ZUMO/3.1+(lang=Managed;+os=Windows;+os_version=6.2.0.9200;+arch=Win32NT;+version=3.1.50105.0) - - windinspectordevmobileappservice.azurewebsites.net 200 77 0 1089 2739 109
2017-01-27T16:26:29 No new trace in the past 1 min(s).
2017-01-27T16:26:34 PID[23292] Verbose Received request: POST https://windinspectordevmobileappservice.azurewebsites.net/.auth/login/aad
2017-01-27T16:29:29 No new trace in the past 1 min(s).
注意看这些日志,当登录调用成功时,我看到“JWT验证成功”,当它没有时,我从未看到这一行并且它超时。我已经在线检查了许多样本,使用了这种身份验证模式,代码对我来说很好看。我也试过通过异步命令Execute方法调用代码来调用,这样我就可以一直异步(up)。
在某些情况下,我还有什么想法可以尝试了解可能导致超时的原因?
我遇到的一个问题是MobileServiceClient的源代码托管在: https://github.com/Azure/azure-mobile-services
但是,此存储库已标记为已弃用(或者至少已弃用移动服务以支持移动应用程序)。我认为这个类仍然是与移动应用程序一起使用的那个?
我有什么办法可以进入代码吗?我是否需要从Git获取源并调试它?