microsoft-authentication-library-for-android icon indicating copy to clipboard operation
microsoft-authentication-library-for-android copied to clipboard

Unclear how to use MSAL Android in idiomatic MVVM architecture

Open pepperprogrammer opened this issue 2 years ago • 1 comments

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 avatar Sep 09 '22 15:09 pepperprogrammer

@pepperprogrammer - Android app architecture recommendations continue to evolve. @neha-bhargava - I suggest we provide a sample that follows the current best practices.

shoatman avatar Oct 10 '22 14:10 shoatman

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.

masztalski avatar Nov 29 '22 13:11 masztalski

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.

negoe avatar May 05 '23 05:05 negoe