Azure应用服务身份验证

时间:2015-12-16 16:57:24

标签: c# azure azure-web-sites azure-mobile-services windows-10-universal

是否有人能够使用Azure App Services找出身份验证?

由于某些奇怪的原因,它不再像处理移动服务中那样处理刷新令牌,我现在缓存的令牌在1小时内到期,这是没用的。

这是一个C#UWP应用,我使用Microsoft帐户登录,我被告知使用OneDrive API登录并检索令牌,然后使用它登录App对我来说也不起作用的服务,例如"您无权访问该目录"。

感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

App Service Mobile的解决方案,即MobileService的更新。现在应该有一个solution

这里复制的代码是:

async Task<string> GetDataAsync()
{
try
{
    return await App.MobileService.InvokeApiAsync<string>("values");
}
catch (MobileServiceInvalidOperationException e)
{
    if (e.Response.StatusCode != HttpStatusCode.Unauthorized)
    {
        throw;
    }
}

// Calling /.auth/refresh will update the tokens in the token store
// and will also return a new mobile authentication token.
JObject refreshJson = (JObject)await App.MobileService.InvokeApiAsync(
    "/.auth/refresh",
    HttpMethod.Get,
    null);

string newToken = refreshJson["authenticationToken"].Value<string>();
App.MobileService.CurrentUser.MobileServiceAuthenticationToken
    = newToken;
return await App.MobileService.InvokeApiAsync<string>("values");
}

希望能节省一些时间!