MicrosoftAccount访问Azure移动服务API的桌面客户端流 [英] Desktop client flow for MicrosoftAccount access to Azure Mobile Service API

查看:115
本文介绍了MicrosoftAccount访问Azure移动服务API的桌面客户端流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已关注Adrian Halls 创建带有Mobile Service API后端的跨平台应用程序.我已经成功从Android,iOS和桌面(WPF)客户端获得对后端的不安全访问.我正在继续使用Authorize属性为API添加安全性.我想使用MicrosoftAccount(以前的护照/实时ID)添加社交身份验证.

I have followed Adrian Halls book to create a cross platform app with a Mobile Service API backend. I have successfully got unsecured access to the backend working from Android, iOS and Desktop (WPF) clients. I am moving on to adding security to the API using the Authorise attribute. I would like to add social authentication using MicrosoftAccount (formerly passport/Live ID).

自从阿德里安(Adrian)写了他的书《 Microsoft.Azure.Mobile.Client》以来,身份验证和授权格局似乎一直在发展.本书中提供的示例不再构建,并且微软的社交身份验证和AAD身份验证似乎已集成到一个API中.

Since Adrian wrote his book the Microsoft.Azure.Mobile.Client and the authentication and authorisation landscape seem to have moved on. The samples given in the book no longer build and Microsoft's social authentication and AAD authentication seem to have been rolled into one API.

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

I have spent days searching for up to date and relevant information but there seems to be lots of stuff on the internet that is either out of date or only shows examples of authenticating using Facebook or Google from Xamarin clients or authenticating against Azure AD.

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

I am using .NET 4.7 and WPF for the desktop app. I am also using Microsoft.Azure.Mobile.Client V4.0.1. and my questions are:

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

  1. Should I be using the Microsoft.Identity.Client to authenticate users from my desktop client; and,

如果可以,我可以指出一个我需要遵循的客户端流程示例,特别是如何获取需要传递给使用该新功能的新MobileServiceClient.LoginAsync()函数的授权令牌.身份提供者和令牌参数?

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?

推荐答案

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

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?

根据您的要求,您想使用对用户进行签名.

According to your requirement, you want to use client-flow authentication with MSA. As I known, MSA authentication uses the Live SDK for signing users.

由于不赞成使用Live SDK,因此您可以利用用于CSharp的OneDrive SDK 进行日志记录使用MSA,您可以按照以下详细步骤来实现此目的:

Since Live SDK is deprecated, you could leverage OneDrive SDK for CSharp for logging with MSA, and you could follow the detailed steps for achieving this purpose:

  • 通过NuGet安装客户端库:

  • Install the client libraries via NuGet:

Microsoft.OneDriveSDK

Microsoft.OneDriveSdk.Authentication

登录 Microsoft帐户开发人员中心并创建您的应用,添加本机应用平台,然后

Log into Microsoft Account Developer Center and create your app, add the native application platform, then Register your app with Microsoft Account.

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

  • Then you could follow the code below and add to your WPF application as follows:

有关用于CSharp的OneDrive SDK的更多详细信息,您可以在此处用于OneDrive SDK的身份验证适配器.

For more details about OneDrive SDK for CSharp, you could refer to here and Authentication Adapter for the OneDrive SDK.

更新:

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

It's my fault. I did not mention that the above code would automatically open a web browser. Per my test, you could configure the parameter returnUrl to https://login.microsoftonline.com/common/oauth2/nativeclient when constructing your MsaAuthenticationProvider instance.

这篇关于MicrosoftAccount访问Azure移动服务API的桌面客户端流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆