Graph-Controls/Samples/WpfNetCoreMsalProviderSample
Shane Weaver 2ade9ac256
Update README (#172)
* Updated READMEs
2021-10-25 15:16:57 -07:00
..
App.xaml Update MsalProvider to use native account broker (#169) 2021-10-25 13:56:19 -07:00
App.xaml.cs Update MsalProvider to use native account broker (#169) 2021-10-25 13:56:19 -07:00
AssemblyInfo.cs Update MsalProvider to use native account broker (#169) 2021-10-25 13:56:19 -07:00
CacheConfig.cs Update MsalProvider to use native account broker (#169) 2021-10-25 13:56:19 -07:00
LoginButton.xaml Update MsalProvider to use native account broker (#169) 2021-10-25 13:56:19 -07:00
LoginButton.xaml.cs Update MsalProvider to use native account broker (#169) 2021-10-25 13:56:19 -07:00
MainWindow.xaml Update MsalProvider to use native account broker (#169) 2021-10-25 13:56:19 -07:00
MainWindow.xaml.cs Update MsalProvider to use native account broker (#169) 2021-10-25 13:56:19 -07:00
README.md Update README (#172) 2021-10-25 15:16:57 -07:00
WpfNetCoreMsalProviderSample.csproj Update MsalProvider to use native account broker (#169) 2021-10-25 13:56:19 -07:00

README.md

MsalProvider Authentication Sample for .NET Core 3.1 WPF apps

This sample demonstrates how to configure the MsalProvider to authenticate consumer MSA and organizational AAD accounts in your apps.

string ClientId = "YOUR-CLIENT-ID-HERE";
string[] Scopes = new string[] { "User.Read" };

var provider = new MsalProvider(ClientId, Scopes, null, false, true);

// Configure the token cache storage for non-UWP applications.
var storageProperties = new StorageCreationPropertiesBuilder(CacheConfig.CacheFileName, CacheConfig.CacheDir)
    .WithLinuxKeyring(
        CacheConfig.LinuxKeyRingSchema,
        CacheConfig.LinuxKeyRingCollection,
        CacheConfig.LinuxKeyRingLabel,
        CacheConfig.LinuxKeyRingAttr1,
        CacheConfig.LinuxKeyRingAttr2)
    .WithMacKeyChain(
        CacheConfig.KeyChainServiceName,
        CacheConfig.KeyChainAccountName)
    .Build();
await provider.InitTokenCacheAsync(storageProperties);

ProviderManager.Instance.GlobalProvider = provider;

await provider.TrySilentSignInAsync();

It uses an IProvider implementation called MsalProvider, which leverages the official Microsoft Authentication Library (MSAL) to enable authentication for MSA and AAD accounts.