Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 1.18 KB

File metadata and controls

31 lines (24 loc) · 1.18 KB

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.