问题描述
我已经阅读了几篇关于将Azure Active Directory登录功能添加到Xamarin PCL项目的文章(例如),但我仍然无法使其正常工作。
I have read several articles on adding Azure Active Directory sign-in functionality to Xamarin PCL projects (e.g. https://blog.xamarin.com/put-adal-xamarin-forms/) but I am still not able to make it work.
有人可以澄清用于Azure B2C AD(用于Xamarin PCL项目)的正确ADAL软件包吗?
Can someone please clarifiy the correct ADAL package to use for Azure B2C AD(for Xamarin PCL project)?
是吗?
Microsoft.IdentityModel.Clients.ActiveDirectory
Microsoft.IdentityModel.Clients.ActiveDirectory
OR
Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory
Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory
谢谢!
推荐答案
感谢@Kaush和@vibronet向我指出正确的方向,从而节省了大量时间。
Thanks to @Kaush and @vibronet for pointing me in the right direction, saving a lot of time.
对于任何想要添加B2C的人登录和登录注册流到Xamarin Forms项目-我能够按如下所示为Android混搭解决方案:
For anyone wanting to add B2C Sign-In & Sign-Up flows to a Xamarin Forms project - I was able to mash-up a solution for Android as follows:
-
在始终将对Microsoft.IdentityModel.Clients.ActiveDirectory的任何引用更改为Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory
At all times change any reference to Microsoft.IdentityModel.Clients.ActiveDirectory to Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory
添加Microsoft.Experimental.IdentityModel.Clients .ActiveDirectory包到所有项目。如果PCL项目中发生兼容性错误,请按照@Kaush所述,使用添加引用手动添加软件包引用。我选择了'portable-net45 + win + wpa81'库。
Add the Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory package to all projects. If a compatibility error occurs in the PCL project then manually add a package reference using 'Add Reference' as described by @Kaush. I chose the 'portable-net45+win+wpa81' library.
按如下所述执行流:
将对 AcquireTokenAsync的调用更改为:
Change the call to 'AcquireTokenAsync' to:
var result = await authContext .AcquireTokenAsync(new string [] {clientId},null,clientId,new Uri(returnUri),platformParams, {Policy_Name_Here});
var result = await authContext.AcquireTokenAsync(new string[] { clientId }, null, clientId, new Uri(returnUri), platformParams, "{Policy_Name_Here}");
注意:
-
确保授权格式为' {Tenant_Name_Here} .onmicrosoft.com'
Ensure the format of the authority is 'https://login.microsoftonline.com/{Tenant_Name_Here}.onmicrosoft.com'
这是基于alpha代码的实验性功能,因此希望它会在不久的将来改变/破坏/发展。
This is experimental based on alpha code so expect it to change / break / evolve in the near future.
这篇关于B2C的正确ADAL软件包-Xamarin PCL项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!