问题
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.
Can someone please clarifiy the correct ADAL package to use for Azure B2C AD(for Xamarin PCL project)?
Is it:
Microsoft.IdentityModel.Clients.ActiveDirectory
OR
Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory
Thanks!
回答1:
Thanks to @Kaush and @vibronet for pointing me in the right direction, saving a lot of time.
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:
At all times change any reference to Microsoft.IdentityModel.Clients.ActiveDirectory to Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory
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.
Implement the flows as described here: https://blog.xamarin.com/put-adal-xamarin-forms/
Change the call to 'AcquireTokenAsync' to:
var result = await authContext.AcquireTokenAsync(new string[] { clientId }, null, clientId, new Uri(returnUri), platformParams, "{Policy_Name_Here}");
Notes:
Ensure the format of the authority is 'https://login.microsoftonline.com/{Tenant_Name_Here}.onmicrosoft.com'
This is experimental based on alpha code so expect it to change / break / evolve in the near future.
回答2:
Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory is the right package for B2C, but the Xamarin scenario wasn't one targeted by this preview. We'll be adding new platforms as we refresh the preview going forward.
回答3:
I would pay heed to what @vibronet says, but having said that (and to get you going), here's my screen shot of all the references that I use in the sample project you mentioned:
The ADAL package version I used was: 3.5.207081303-alpha (Prerelease), nuget did not add it to my PCL library, I ended up adding the reference explicitly via the 'Add Reference' and browsing to the package, maybe you could try the same.
Lastly, I had to add the extraQueryParameters as specified in here
Let me know how you go...
来源:https://stackoverflow.com/questions/33028388/correct-adal-package-for-b2c-xamarin-pcl-project