CommunityToolkit / Graph-Controls

Set of Helpers and Controls for Windows development using the Microsoft Graph.
https://docs.microsoft.com/en-us/windows/communitytoolkit/graph/overview
Other
155 stars 39 forks source link

Update MsalProvider to use native account broker #169

Closed shweaver-MSFT closed 3 years ago

shweaver-MSFT commented 3 years ago

Fixes #168 Fixes #170

PR Type

What kind of change does this PR introduce?

What is the current behavior?

Currently the MsalProvider does not invoke the native account broker in Windows, even when it is available. Users always see the web-based prompt, even when using the MsalProvider in UWP.

What is the new behavior?

I've made a few changes:

  1. Updated the CommunityToolkit.Authentication.Msal package to multi-target uap10.0, netstandard3.1, and net5.0-windows10.0.17763.0 as well as the existing target for netstandard2.0. This enables the Windows account broker to work for those additional frameworks.
  2. Updated the MsalProvider to use the appropriate APIs depending on where the app is running (UWP/Net5-Windows or otherwise).
  3. Added a new constructor for MsalProvider that accepts a pre-configured PublicClientApplication object.
  4. Added a new sample to demonstrate using MsalProvider in NetCore3.1 applications.
  5. Updated MsalNet5WindowsMsalProviderSample to show token cache pattern.

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

A good way to test is by firing up the UwpMsalProviderSample, WpfNet5WindowsMsalProviderSample, and WpfNetCoreMsalProviderSample samples and compare the experience.

More info on the cache situation can be found here: https://github.com/AzureAD/microsoft-authentication-extensions-for-dotnet/wiki/Cross-platform-Token-Cache

ghost commented 3 years ago

Thanks shweaver-MSFT for opening a Pull Request! The reviewers will test the PR and highlight if there is any merge conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌