Lighter Spin on ADAL in Xamarin Forms

tl;dr

new-up the elusive “PlatformParameters” in your AppDeligate.cs::FinishedLoading / MainActivity.cs::OnCreate
 

ts;wm (too short; want more ; )

thankfully we have solid writeups on ADAL with XF… this post is just me trying to boil it down to essence and PCL as much as possible…
(BTW: ADAL = Active Directory Auth Lib… i needed it for PowerBI embedding)

  1. http://www.appzinside.com/2016/02/22/implement-adal-for-cross-platform-xamarin-applications/
  2. https://blog.xamarin.com/authenticate-mobile-apps-using-microsoft-authentication-library/

the first post keeps the platform specific surface area pretty minimal but also winds up wrappering the stock ADAL classes quite a bit…
the second post seems pretty minimal and leverages CustomRenderers for the right timing to grab this context… seems like a good general trick to tuck away…
 

the approach i came to is grabbing this context right up front in app initialization and then providing it through dependency injection later…
both pieces of that are basically one liners which feels nice
also it’s now conveniently available to other services should needs arise…
and theoretically we’ve kept things clean for TDD but honestly i don’t readily see how to test this flow since it requires interactive auth… i’ll have to read up on how people generally recommend mocking this kind of thing
 

iOS AppDeligate.cs::FinishedLoading()

Android MainActivity.cs::OnCreate

then later in calling code just reference via DI