0

我有一个 javascript windows 商店应用程序,它通过 Microsoft.Preview.WindowsAzure.ActiveDirectory.Authentication 库与 AAD 进行身份验证。它适用于托管在 Azure 中的 ASP.NET WebAPI。它工作正常,它提示用户登录(Windows登录服务),一旦登录,用户就可以工作并且不会被要求再次登录。我发现的问题是,当用户有一段时间不使用该应用程序时,我不确定,但我认为在 20 到 30 分钟之间,应用程序就会停止运行。它不响应用户查询。我认为与 webApi 的通信丢失了,我不确定应用程序获取的令牌是否已过期或 Azure 本身切断了连接。

这就是我获得令牌的方式

var authcontext = new aal.AuthenticationContext(audience);
aal.DefaultTokenCache().clear();
return authcontext.acquireTokenAsync(resource, clientID, redirectUri.absoluteUri, "", null).then(function (result) {
     if (aal.AuthenticationStatus.succeeded == result.status) {
         accessToken = result.accessToken;
         return true;
     }
}

和 webApi 调用

var uri = new Windows.Foundation.Uri(apiUrl + apiName);
        var httpClient = new Windows.Web.Http.HttpClient();

        httpClient.defaultRequestHeaders.authorization =
            new Windows.Web.Http.Headers.HttpCredentialsHeaderValue("Bearer", accessToken);

        return httpClient.getAsync(uri).then(function (response) {
            if (response.isSuccessStatusCode == true)
                return response.content.readAsStringAsync().then(function (responseText) {
                    var array = JSON.parse(responseText);
                    return array;
                });
            else
            {
                var md = new Windows.UI.Popups.MessageDialog(response, "Error");
                md.showAsync();
            }
        });

我试过添加

<sessionTokenRequirement lifetime="96:00:00" /><cookieHandler persistentSessionLifetime="60.0:0:0" requireSsl="true" />在 web.config 中,但仍然出现错误。

我正在尝试将 ADAL 新版本添加到项目中,但未成功,因为我阅读了有关刷新令牌的内容,我正在研究它,但没有找到任何 Windows 商店应用程序的示例。

关于问题原因以及如何解决的任何线索?

谢谢你的时间。

4

1 回答 1

0

您使用的库版本过时且不受支持。此外,cookie 在 api 通信中没有任何作用。我建议切换到最新的稳定 ADAL。使用 ADAL 的 Windows 应用商店示例:https ://github.com/AzureADSamples/NativeClient-WindowsStore

于 2015-03-05T16:13:51.520 回答