简体   繁体   English

在AAD B2C中将刷新令牌与Azure App Service和Xamarin.Forms一起使用

[英]Using a refresh token in AAD B2C with Azure App Service and Xamarin.Forms

I'm trying to get a refresh token set up in my Xamarin.Forms app using AAD B2C. 我正在尝试使用AAD B2C在Xamarin.Forms应用程序中设置刷新令牌。 I've got everything set up but run into issues when calling LoginAsync on my MobileServiceClient . 我已经进行了所有设置,但是在MobileServiceClient上调用LoginAsync时遇到了问题。 All of the docs and examples I can find show to update my LoginAsync method to this: 我可以找到的所有文档和示例都显示了如何将我的LoginAsync方法更新为:

var user = await App.MobileServiceClient.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory,
    new Dictionary<string, string>() { { "response_type", "code id_token" } });

Except that the MobileServiceClient does not take a Dictionary<string, string> for the second parameter. 除了MobileServiceClient的第二个参数不使用Dictionary<string, string> It takes a JObject . 它需要一个JObject Here's what my current code looks like: 这是我当前的代码:

var authResult = await App.AuthenticationClient.AcquireTokenAsync(Constants.Scopes, "", UiOptions.SelectAccount, string.Empty, null, Constants.Authority, Constants.Policy);

var payload = new JObject();
payload["access_token"] = authResult.Token;

var user = await App.MobileServiceClient.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, payload);

I can not find an example use the JObject anywhere. 我找不到在任何地方使用JObject的示例。
It is as simple as adding payload["response_type"] = "code id_token"; 就像添加payload["response_type"] = "code id_token";一样简单payload["response_type"] = "code id_token"; to my payload? 到我的有效载荷?

AFAIK, Mobile Apps support two authentication flows ( client-managed flow and server-managed flow ). AFAIK,Mobile Apps支持两个身份验证流程( 客户端管理的流程服务器管理的流程 )。

Client-managed authentication 客户端管理的身份验证

Your app can independently contact the identity provider and then provide the returned token during login with your backend . 您的应用程序可以独立地与身份提供者联系,然后在与后端登录时提供返回的令牌 This client flow enables you to provide a single sign-on experience for users or to retrieve additional user data from the identity provider. 该客户端流使您能够为用户提供单点登录体验,或者从身份提供者那里检索其他用户数据。

After you retrieved the token, then you would login with your azure mobile backend by passing the token into a JObject instance as follows: 检索令牌后,可以通过将令牌传递到JObject实例中来使用azure移动后端登录,如下所示:

JObject payload = new JObject();
payload["access_token"] = ar.AccessToken;
var user = await client.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, payload);

For more details about other identity providers via client-flow authentication, you could refer to Client-managed authentication . 有关通过客户端流身份验证的其他身份提供者的更多详细信息,可以参考客户端管理的身份验证

Server-managed authentication 服务器管理的身份验证

Your app directly contacts your mobile backend, then your azure mobile backend contacts the identity provider and provide you with the logged user. 您的应用程序直接与您的移动后端联系,然后您的Azure移动后端与身份提供者联系并为您提供登录用户。

  • For Xamarin.Forms UWP app, you could login as follows: 对于Xamarin.Forms UWP应用,您可以按以下方式登录:

在此处输入图片说明

  • For Xamarin.Forms IOS app, you could login as follows: 对于Xamarin.Forms IOS应用程序,您可以按以下方式登录: 在此处输入图片说明

For more details about server-managed authentication in Xamarin.Forms, you could refer to Add authentication to your Xamarin Forms app . 有关Xamarin.Forms中服务器管理的身份验证的更多详细信息,可以参考将身份验证添加到Xamarin Forms应用程序

UPDATE: 更新:

I have checked that if you call MobileServiceClient.LoginAsync in PCL, you could not see any extensions for LoginAsync . 我已经检查过,如果您在PCL中调用MobileServiceClient.LoginAsync ,则看不到LoginAsync任何扩展名。 As you could see, there are many extension LoginAsync methods in the Microsoft.WindowsAzure.Mobile.Ext.dll for each platform. 如您所见,每个平台的Microsoft.WindowsAzure.Mobile.Ext.dll都有许多扩展LoginAsync方法。 You need to define the IAuthenticate interface and implement it in each of your app (uwp, android, ios, etc.), for more details you could refer to here . 您需要定义IAuthenticate接口并在每个应用程序(uwp,android,ios等)中实现它,有关更多详细信息,请参见此处

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Azure AD B2C的Xamarin.Forms应用仅显示Microsoft登录 - Xamarin.Forms app using Azure AD B2C only showing Microsoft login 401 在 Xamarin.Forms 上未经 Azure b2c 授权 - 401 Unauthorized with Azure b2c on Xamarin.Forms Azure AD B2C在Xamarin.Forms iOS应用中指定多个身份提供程序 - Azure AD B2C Specify multiple Identity Providers in Xamarin.Forms iOS app Azure B2C 忘记密码未显示在 Xamarin.Forms UWP 应用程序上 - Azure B2C Forgot password is not showing on Xamarin.Forms UWP app 如何使用Azure AD B2C身份验证开发多用户Xamarin.Forms应用 - How to develop a multi-user Xamarin.Forms app with Azure AD B2C authentication 在 Xamarin.Forms 中使用 MSAL 获取 Azure B2C SignUpSignIn 应用程序声明 - Getting Azure B2C SignUpSignIn Application Claims using MSAL in Xamarin.Forms Azure AD B2C 上 Xamarin.Forms 抛出错误 B2C '权限' Uri 应该至少有 3 个段 - Azure AD B2C on Xamarin.Forms throwing error B2C 'authority' Uri should have at least 3 segments 如何使用 MSAL 将现有 Azure AD B2C 集成到 Xamarin forms 应用程序中? - How to Integrate existing Azure AD B2C into a Xamarin forms app using MSAL? Xamarin.forms 的 Azure AD B2C“Safari 无法打开页面,因为地址无效”? - Azure AD B2C for Xamarin.forms "Safari cannot open the page because the address is invalid"? Xamarin.forms和Azure AD B2C-缺少PublicClientApplication.PlatformParameters? - Xamarin.forms and Azure AD B2C - missing PublicClientApplication.PlatformParameters?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM