ADAL and how to sign in with Microsoft accounts in Xamarin.iOS
One the latest bits we added to HealthClinic.biz suite is Azure’s Active Directory Authentication (ADAL from now on). Basically, you can authenticate users by their Microsoft account, and let them access the app or not. You can do some other things, but our mainly goal was that one. For instance, we added also Touch ID so your fingerprint is saved to avoid entering the credentials once and again. Superb.
However, I got the feeling I should extract all that I learned into a simple sample (try to read it without spaces, new buzzword coming 🙂 ) just to clarify the concepts needed to achieve such authentication, plus best practices on how to handle, for example, recovering the session when waking the app up again from scratch.
MicrosoftGraphAuthSample does just that. And this’ the list of key points:
- All the auth. logic is covered within MicrosoftAuthenticationService.cs
- When an user successfully authenticates, on a future run the app retrieves the “TokenCache” from storage in order to sign-in silently, as one expects from a real app
- The entire flow happens also (or at least I’ve tried to) as one expect: the UI gets disabled while auth. happens, the main page (“Home”) appears in a modal way to let user know he’s in someway entered on a different place from the sign-in one (well, it’s actually maybe not recommended for real apps, but just for the sake of the demo), etc.
Finally, I wanted to say thanks to Brett Samblanet, from Microsoft’s Azure Team, as he pointed me to the correct ADAL package in NuGet, which solved an issue I had which was rejecting the communication when trying to log in. Thanks so much Brett! 🙂
Maybe this demo can fit in Azure’s documentation portal, I’m looking to the “Add Sign-In to an iOS App (Coming Soon)”. 😉