microsoft-authentication-library-for-android
microsoft-authentication-library-for-android copied to clipboard
Unclear how to use MSAL Android in idiomatic MVVM architecture
Hi,
The code samples and documentation don't seem to show how MSAL Android can fit into a scalable app architecture, such as the one recommended in the Android docs: https://developer.android.com/topic/architecture#recommended-app-arch
I've seen examples where the PublicClientApplication
is instantiated and used in an Activity
or a Fragment
file, but these examples have some issues:
- Fragments should only contain UI logic
- Activity files should contain minimal logic
- The user's account information, tokens, etc will not be persisted through configuration changes such as screen rotation
- This doesn't show an obvious, clean way to share MSAL-related state (such as
PublicClientApplication
objects or tokens) between ViewModels or in the data layer
What is the intended approach to integrating MSAL Android into such an app architecture? E.g., does it work best with a DI system, as a singleton, or something else? Or, is it wrong to try to make it fit into Google's recommended approach?
Please let me know if I should reopen this issue in a different repo, such as one of the documentation repos.
Thanks!
@pepperprogrammer - Android app architecture recommendations continue to evolve. @neha-bhargava - I suggest we provide a sample that follows the current best practices.
I have wrapped whole B2C logic in data layer into RxJava2. Object holding all msal related variables is singleton. Only exception in whole architecture is observing liveData event from viewModel to call from viewModel method causing login by passing to it instance of activity. Hard to see another way to execute it as it requires webView.
Thank you for taking the time to provide us with your valuable feedback. We will provide updates as soon as we have new documentation and sample to support your requirements.