MicrosoftAccount 访问 Azure 移动服务的桌面客户端流程 API

Desktop client flow for MicrosoftAccount access to Azure Mobile Service API

我跟随 Adrian Halls book 创建了一个带有移动服务 API 后端的跨平台应用程序。我已经成功地从 Android、iOS 和桌面 (WPF) 客户端获得了对后端的不安全访问。我将继续使用 Authorize 属性向 API 添加安全性。我想使用 MicrosoftAccount(以前的 passport/Live ID)添加社交身份验证。

自从 Adrian 写了他的书 Microsoft.Azure.Mobile.Client 以来,身份验证和授权领域似乎已经发生了变化。书中给出的示例不再构建,微软的社交认证和AAD认证好像已经合二为一了API.

我花了几天时间搜索最新的相关信息,但互联网上似乎有很多东西已经过时或仅显示使用 Facebook 或 Xamarin Google 进行身份验证的示例客户端或针对 Azure AD 进行身份验证。

我正在为桌面应用程序使用 .NET 4.7 和 WPF。我也在使用 Microsoft.Azure.Mobile.Client V4.0.1。我的问题是:

  1. 我应该使用 Microsoft.Identity.Client 从我的桌面客户端验证用户吗?并且,

  2. 如果可以,有人可以指出我需要遵循的客户端流程示例,具体来说,我如何获得需要传递给新 MobileServiceClient.LoginAsync 的授权令牌() 使用标识提供程序和令牌参数的函数?

我处在类似的情况下 - 这里是我脑海中的总结 - 目前有两个安全库正在使用授权 - ADAL 和 MSAL。

阿达尔 这是第一个出来的库,像B2C这样的服务必须分别使用这个库来处理。

MSAL 一个安全框架来统治他们! https://github.com/Azure-Samples/active-directory-xamarin-native-v2 该库具有上线许可证,但从技术上讲它仍处于测试阶段。

前往Mobile.azure.com for the last info in creating a mobile application, and this article on a V2 endpoint

当您注册授权申请时 - 有两个类别,一个是 "Converged" 申请,另一个是 "Live SDK application"(请参阅 https://apps.dev.microsoft.com/#/appList) - 我不明白为什么他们会选择这些名称了解。重要翻译 - 融合应用程序仅适用于 MSAL,另一个仅适用于 ADAL。这对您使身份验证正常工作大有帮助,因为应用程序/客户端 ID 必须与正确的 SDK 匹配,因此端点也必须匹配。

最后,我们选择暂时使用 ADAL,因为我们在使用 MSAL 时遇到了问题。然而,MSAL 是未来,因为所有服务都将被合并,它应该是一个更易于使用的 SDK。

以下是我保留的一些链接,所有链接都涉及 ADAL 或 MSAL:

http://aka.ms/aadv2

https://azure.microsoft.com/develop/identity

https://docs.microsoft.com/en-ca/azure/active-directory/develop/active-directory-authentication-scenarios#native-application-to-web-api

https://github.com/AzureAD

https://github.com/AzureAD/microsoft-authentication-library-for-dotnet

这些链接大约一个月前 - HTH

If so can someone point me to an example of the client flow that I need to follow, specifically how do I get the authorisation token that I need to pass to the new MobileServiceClient.LoginAsync() function that uses the identification provider and token parameters?

根据您的要求,您要使用client-flow authentication with MSA. As I known, MSA authentication uses the Live SDK for signing users.

由于 Live SDK 已弃用,您可以利用 OneDrive SDK for CSharp 使用 MSA 进行日志记录,您可以按照详细步骤实现此目的:

  • 然后您可以按照下面的代码添加到您的 WPF 应用程序中,如下所示:

有关OneDrive SDK for CSharp的更多详细信息,您可以参考here and Authentication Adapter for the OneDrive SDK

更新:

这是我的错。我没有提到上面的代码会自动打开一个网络浏览器。根据我的测试,您可以在构建 MsaAuthenticationProvider 实例时将参数 returnUrl 配置为 https://login.microsoftonline.com/common/oauth2/nativeclient