├── active-directory-b2c-wpf ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── App.xaml ├── TokenCacheHelper.cs ├── MainWindow.xaml ├── App.xaml.cs ├── active-directory-b2c-wpf.csproj └── MainWindow.xaml.cs ├── active-directory-b2c-wpf.sln ├── LICENSE ├── .gitattributes ├── .gitignore └── README.md /active-directory-b2c-wpf/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /active-directory-b2c-wpf/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /active-directory-b2c-wpf.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26403.7 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "active-directory-b2c-wpf", "active-directory-b2c-wpf\active-directory-b2c-wpf.csproj", "{9A4269AF-7862-482C-A9FC-98D3542C4129}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {9A4269AF-7862-482C-A9FC-98D3542C4129}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {9A4269AF-7862-482C-A9FC-98D3542C4129}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {9A4269AF-7862-482C-A9FC-98D3542C4129}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {9A4269AF-7862-482C-A9FC-98D3542C4129}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /active-directory-b2c-wpf/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace active_directory_b2c_wpf.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.6.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /active-directory-b2c-wpf/TokenCacheHelper.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | using System.IO; 5 | using System.Security.Cryptography; 6 | using Microsoft.Identity.Client; 7 | 8 | namespace active_directory_b2c_wpf 9 | { 10 | static class TokenCacheHelper 11 | { 12 | /// 13 | /// Path to the token cache 14 | /// 15 | public static readonly string CacheFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location + ".msalcache.bin"; 16 | 17 | private static readonly object FileLock = new object(); 18 | 19 | public static void BeforeAccessNotification(TokenCacheNotificationArgs args) 20 | { 21 | lock (FileLock) 22 | { 23 | args.TokenCache.DeserializeMsalV3(File.Exists(CacheFilePath) 24 | ? ProtectedData.Unprotect(File.ReadAllBytes(CacheFilePath), 25 | null, 26 | DataProtectionScope.CurrentUser) 27 | : null); 28 | } 29 | } 30 | 31 | public static void AfterAccessNotification(TokenCacheNotificationArgs args) 32 | { 33 | // if the access operation resulted in a cache update 34 | if (args.HasStateChanged) 35 | { 36 | lock (FileLock) 37 | { 38 | // reflect changes in the persistent store 39 | File.WriteAllBytes(CacheFilePath, 40 | ProtectedData.Protect(args.TokenCache.SerializeMsalV3(), 41 | null, 42 | DataProtectionScope.CurrentUser)); 43 | } 44 | } 45 | } 46 | 47 | internal static void Bind(ITokenCache tokenCache) 48 | { 49 | tokenCache.SetBeforeAccess(BeforeAccessNotification); 50 | tokenCache.SetAfterAccess(AfterAccessNotification); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /active-directory-b2c-wpf/MainWindow.xaml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |