0

是否有人能够使用Azure应用服务计算身份验证?Azure应用服务身份验证

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

这是一个C#UWP应用程序,我使用Microsoft帐户作为登录名,我被告知要使用OneDrive API登录并检索令牌,然后使用它登录到App Services,而不是也为我工作,像“你没有访问目录的权限”这样的错误。

任何帮助表示赞赏。

+0

登录令牌的1小时到期是一个已知问题,正在修复中。如果您可以提供有关“您无权访问目录”问题的更多信息,我们可能会帮助您找到解决方法。当你得到这个错误时,你能够提供一个HTTP跟踪吗?另外,请尝试在管理门户中为您的应用程序启用应用程序日志记录,并查看是否有任何有趣的警告/错误消息。 –

+0

OneDrive SDK或移动应用程序客户端是否抛出“您无权访问目录”?信息? – phillipv

+0

Phillip在MSDN的帖子中回答了这个问题,猜测这是你的大声笑。 但基本上,我在我的JObject中使用“authentcationToken”作为密钥,我应该使用“access_token”,它可以工作,现在允许我使用从OneDrive获得的令牌登录到App Services。 但是我想说明的是,文档明确指出要为Microsoft帐户使用“authenticationToken”而不是“access_token”,这似乎是错误的,并且是导致许可问题的原因。到目前为止,与MobileServices/AppServices有关的文档一直非常混乱。 –

回答

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"); 
} 

希望这样可以节省别人的时间!