Skip to content

Commit af5a9f6

Browse files
committed
Aligning source code of TodoListClient in this sample with the [active-directory-dotnet-native-desktop](https://github.com/azure-samples/active-directory-dotnet-native-desktop) sample as only the App.Config should change.
- Changing the license to MIT - Adding a label to show the signed-in user.
1 parent d9b6c20 commit af5a9f6

File tree

6 files changed

+213
-161
lines changed

6 files changed

+213
-161
lines changed

TodoListClient/FileCache.cs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
1-
using Microsoft.IdentityModel.Clients.ActiveDirectory;
2-
using System;
3-
using System.Collections.Generic;
1+
/*
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2015 Microsoft Corporation
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
*/
24+
25+
using Microsoft.IdentityModel.Clients.ActiveDirectory;
426
using System.IO;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
8-
using System.Security;
927
using System.Security.Cryptography;
1028

1129
namespace TodoListClient
@@ -20,7 +38,7 @@ class FileCache : TokenCache
2038

2139
// Initializes the cache against a local file.
2240
// If the file is already rpesent, it loads its content in the ADAL cache
23-
public FileCache(string filePath = @".\TokenCache.dat")
41+
public FileCache(string filePath=@".\TokenCache.dat")
2442
{
2543
CacheFilePath = filePath;
2644
this.AfterAccess = AfterAccessNotification;
@@ -40,11 +58,11 @@ public override void Clear()
4058

4159
// Triggered right before ADAL needs to access the cache.
4260
// Reload the cache from the persistent store in case it changed since the last access.
43-
void BeforeAccessNotification(TokenCacheNotificationArgs args)
61+
void BeforeAccessNotification(TokenCacheNotificationArgs args)
4462
{
4563
lock (FileLock)
4664
{
47-
this.Deserialize(File.Exists(CacheFilePath) ? ProtectedData.Unprotect(File.ReadAllBytes(CacheFilePath), null, DataProtectionScope.CurrentUser) : null);
65+
this.Deserialize(File.Exists(CacheFilePath) ? ProtectedData.Unprotect(File.ReadAllBytes(CacheFilePath),null,DataProtectionScope.CurrentUser) : null);
4866
}
4967
}
5068

@@ -55,14 +73,14 @@ void AfterAccessNotification(TokenCacheNotificationArgs args)
5573
if (this.HasStateChanged)
5674
{
5775
lock (FileLock)
58-
{
76+
{
5977
// reflect changes in the persistent store
60-
File.WriteAllBytes(CacheFilePath, ProtectedData.Protect(this.Serialize(), null, DataProtectionScope.CurrentUser));
78+
File.WriteAllBytes(CacheFilePath, ProtectedData.Protect(this.Serialize(),null,DataProtectionScope.CurrentUser));
6179
// once the write operation took place, restore the HasStateChanged bit to false
6280
this.HasStateChanged = false;
63-
}
81+
}
6482
}
6583
}
6684
}
6785

68-
}
86+
}

TodoListClient/MainWindow.xaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818
</VisualBrush>
1919
</Grid.Resources>
2020
<StackPanel Grid.Row="0" Margin="5" VerticalAlignment="Top" Height="351">
21-
<Button HorizontalAlignment="Right" Content="Sign In" Margin="0" Click="SignIn" x:Name="SignInButton" Width="80" Height="30">
22-
<Button.Style>
23-
<Style TargetType="{x:Type Button}">
24-
<!-- "<Setter Property="IsEnabled" Value="False" /> -->
25-
</Style>
26-
</Button.Style>
27-
28-
</Button>
21+
<Grid HorizontalAlignment="Left" Width="346">
22+
<Label HorizontalAlignment="Left" Content="Not Signed" Margin="0" x:Name="UserName" Width="261" Height="30"/>
23+
<Button HorizontalAlignment="Right" Content="Sign In" Margin="0" Click="SignIn" x:Name="SignInButton" Width="80" Height="30">
24+
<Button.Style>
25+
<Style TargetType="{x:Type Button}">
26+
<!-- "<Setter Property="IsEnabled" Value="False" /> -->
27+
</Style>
28+
</Button.Style>
29+
</Button>
30+
</Grid>
2931
<GroupBox Margin="0,0,0,0" Header="Create a To Do item">
3032

3133
<Grid Margin="0" HorizontalAlignment="Left" Width="388" >

0 commit comments

Comments
 (0)