File tree Expand file tree Collapse file tree 8 files changed +40
-117
lines changed
1. Desktop app calls Web API
2. Web API now calls Microsoft Graph Expand file tree Collapse file tree 8 files changed +40
-117
lines changed Original file line number Diff line number Diff line change 22// Licensed under the MIT License.
33
44using Microsoft . Identity . Client ;
5+ using Microsoft . Identity . Client . Desktop ;
6+ using Microsoft . Identity . Client . Extensions . Msal ;
57using Newtonsoft . Json ;
68using System . Collections . Generic ;
79using System . Configuration ;
@@ -62,12 +64,22 @@ private static string TodoListApiAddress
6264 public MainWindow ( )
6365 {
6466 InitializeComponent ( ) ;
67+
68+ // Create the app
6569 _app = PublicClientApplicationBuilder . Create ( ClientId )
6670 . WithAuthority ( Authority )
6771 . WithRedirectUri ( "http://localhost" ) // needed only for the system browser
6872 . Build ( ) ;
6973
70- TokenCacheHelper . EnableSerialization ( _app . UserTokenCache ) ;
74+ // Add token cache serialization
75+ var storageProperties =
76+ new StorageCreationPropertiesBuilder (
77+ "ClientConsoleApp" ,
78+ Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) )
79+ . Build ( ) ;
80+ var cacheHelper = MsalCacheHelper . CreateAsync ( storageProperties ) . GetAwaiter ( ) . GetResult ( ) ;
81+ cacheHelper . RegisterCache ( _app . UserTokenCache ) ;
82+
7183 GetTodoList ( ) ;
7284 }
7385
Original file line number Diff line number Diff line change 22
33 <PropertyGroup >
44 <OutputType >WinExe</OutputType >
5- <TargetFramework >net5-windows10.0.17763.0 </TargetFramework >
5+ <TargetFramework >net472 </TargetFramework >
66 <UseWPF >true</UseWPF >
77 </PropertyGroup >
88
99 <ItemGroup >
10- <PackageReference Include =" Microsoft.Identity.Client" Version =" 4.38.0" />
11- <PackageReference Include =" Newtonsoft.Json" Version =" 13.0.1" />
10+ <PackageReference Include =" Microsoft.Identity.Client" Version =" 4.53.0" />
11+ <PackageReference Include =" Microsoft.Identity.Client.Desktop" Version =" 4.53.0" />
12+ <PackageReference Include =" Microsoft.Identity.Client.Extensions.Msal" Version =" 2.29.0" />
13+ <PackageReference Include =" Newtonsoft.Json" Version =" 13.0.1" />
14+ </ItemGroup >
15+
16+ <ItemGroup >
17+ <Reference Include =" System.Configuration" />
1218 </ItemGroup >
1319
1420 <ItemGroup >
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 77 </PropertyGroup >
88
99 <ItemGroup >
10- <PackageReference Include =" Microsoft.Identity.Web" Version =" 2.8 .0" />
10+ <PackageReference Include =" Microsoft.Identity.Web" Version =" 2.10 .0" />
1111 </ItemGroup >
1212</Project >
Original file line number Diff line number Diff line change 22// Licensed under the MIT License.
33
44using Microsoft . Identity . Client ;
5+ using Microsoft . Identity . Client . Extensions . Msal ;
56using Newtonsoft . Json ;
67using System . Collections . Generic ;
78using System . Configuration ;
@@ -65,7 +66,15 @@ public MainWindow()
6566 . WithDefaultRedirectUri ( )
6667 . Build ( ) ;
6768
68- TokenCacheHelper . EnableSerialization ( _app . UserTokenCache ) ;
69+ // Add token cache serialization
70+ var storageProperties =
71+ new StorageCreationPropertiesBuilder (
72+ "ClientConsoleApp" ,
73+ Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) )
74+ . Build ( ) ;
75+ var cacheHelper = MsalCacheHelper . CreateAsync ( storageProperties ) . GetAwaiter ( ) . GetResult ( ) ;
76+ cacheHelper . RegisterCache ( _app . UserTokenCache ) ;
77+
6978 GetTodoList ( ) ;
7079 }
7180
Original file line number Diff line number Diff line change 6464 <SubType >Designer</SubType >
6565 </ApplicationDefinition >
6666 <Compile Include =" TodoItem.cs" />
67- <Compile Include =" TokenCacheHelper.cs" />
6867 <Page Include =" MainWindow.xaml" >
6968 <Generator >MSBuild:Compile</Generator >
7069 <SubType >Designer</SubType >
109108 </ItemGroup >
110109 <ItemGroup >
111110 <PackageReference Include =" Microsoft.Identity.Client" >
112- <Version >4.43.1</Version >
111+ <Version >4.53.0</Version >
112+ </PackageReference >
113+ <PackageReference Include =" Microsoft.Identity.Client.Extensions.Msal" >
114+ <Version >2.29.0</Version >
113115 </PackageReference >
114116 <PackageReference Include =" Newtonsoft.Json" >
115- <Version >13.0.1 </Version >
117+ <Version >13.0.3 </Version >
116118 </PackageReference >
117119 </ItemGroup >
118120 <Import Project =" $(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1111 </ItemGroup >
1212
1313 <ItemGroup >
14- <PackageReference Include =" Microsoft.Identity.Web.MicrosoftGraph" Version =" 2.8 .0" />
15- <PackageReference Include =" Microsoft.Identity.Web" Version =" 2.8 .0" />
14+ <PackageReference Include =" Microsoft.Identity.Web.MicrosoftGraph" Version =" 2.10 .0" />
15+ <PackageReference Include =" Microsoft.Identity.Web" Version =" 2.10 .0" />
1616 </ItemGroup >
1717
1818</Project >
You can’t perform that action at this time.
0 commit comments