我们目前正在编写一个Xamarin Forms Azure Mobile应用程序,使用客户端流程,AAD身份验证,刷新令牌等。 其中大部分都按预期工作。但是,退出应用程序无法正常工作。它完成了Android和iOS的注销过程 - 但是在重定向到登录屏幕时,点击登录将永远不会按预期提示用户使用Microsoft登录,它会直接签回应用程序。
为了添加一点背景知识,这款应用已根据Adrian Hall的书实施,
当前链接:https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/
使用上述选项和配置。
我还阅读了Zumo(也是Adrian Hall)30天的博客,以及我在这里找到的与此相关的每一篇文章。
我目前的退出代码如下:
public async Task LogoutAsync()
{
var loginProvider = DependencyService.Get<ILoginProvider>();
client.CurrentUser = loginProvider.RetrieveTokenFromSecureStore();
var authUri = new Uri($"{client.MobileAppUri}/.auth/logout");
using (var httpClient = new HttpClient())
{
if (IsTokenExpired(client.CurrentUser.MobileServiceAuthenticationToken))
{
var refreshed = await client.RefreshUserAsync();
}
httpClient.DefaultRequestHeaders.Add("X-ZUMO-AUTH", client.CurrentUser.MobileServiceAuthenticationToken);
await httpClient.GetAsync(authUri);
}
// Remove the token from the cache
loginProvider.RemoveTokenFromSecureStore();
//Remove the cookies from the device - so that the webview does not hold on to the originals
DependencyService.Get<ICookieService>().ClearCookies();
// Remove the token from the MobileServiceClient
await client.LogoutAsync();
}
据我所知,这包括我到目前为止发现的所有内容 - 即调用/.auth/logout端点,在本地删除令牌,清除设备中的cookie(当我们在webview中登录时)和最后从MobileServiceClient调用LogoutAsync()方法。
我错过了什么吗?或者有没有办法可以强制退出这个环境?据我所知,你无法“使OAuth令牌无效”,你必须等到它过期 - 但在我看来,/。auth / logout端点应该在Azure环境中处理这个问题?虽然我不确定到什么程度。
感谢任何帮助。
答案 0 :(得分:0)
我们目前正在编写一个Xamarin Forms Azure Mobile应用程序,使用客户端流程,AAD身份验证,刷新令牌等。大部分内容都按预期工作。但是,退出应用程序无法正常工作。
我假设如果您使用服务器流来记录AAD,则注销处理可能会按预期工作。正如您所描述的那样,您使用了客户端流,因为您已清除令牌的客户端缓存,我认为问题可能是由与LoginAsync相关的(ADAL部分)逻辑代码引起的,您需要检查代码,或者您可以提供日志记录我们的相关代码可以缩小这个问题。