Skip to content

Commit 2945c69

Browse files
committed
Adapting the code to the latest V2 requirements in term of scopes.
1 parent 590e013 commit 2945c69

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

TodoListClient/MainWindow.xaml.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ public partial class MainWindow : Window
4747
private HttpClient httpClient = new HttpClient();
4848
private PublicClientApplication app = null;
4949

50+
private string Scope
51+
{
52+
get
53+
{
54+
return $"api://{clientId}/access_as_user";
55+
}
56+
}
5057
protected override async void OnInitialized(EventArgs e)
5158
{
5259
base.OnInitialized(e);
@@ -62,7 +69,7 @@ protected override async void OnInitialized(EventArgs e)
6269
// get a token for the user without showing a UI.
6370
try
6471
{
65-
result = await app.AcquireTokenSilentAsync(new string[] { clientId }, app.Users.FirstOrDefault());
72+
result = await app.AcquireTokenSilentAsync(new string[] { Scope }, app.Users.FirstOrDefault());
6673
// If we got here, a valid token is in the cache - or MSAL was able to get a new oen via refresh token.
6774
// Proceed to fetch the user's tasks from the TodoListService via the GetTodoList() method.
6875

@@ -109,7 +116,7 @@ private async void GetTodoList()
109116
// without invoking any UI prompt. AcquireTokenSilentAsync forces
110117
// MSAL to throw an exception if it cannot get a token silently.
111118

112-
result = await app.AcquireTokenSilentAsync(new string[] { clientId }, app.Users.FirstOrDefault());
119+
result = await app.AcquireTokenSilentAsync(new string[] { Scope }, app.Users.FirstOrDefault());
113120
}
114121
catch (MsalException ex)
115122
{
@@ -173,7 +180,7 @@ private async void AddTodoItem(object sender, RoutedEventArgs e)
173180
AuthenticationResult result = null;
174181
try
175182
{
176-
result = await app.AcquireTokenSilentAsync(new string[] { clientId }, app.Users.FirstOrDefault());
183+
result = await app.AcquireTokenSilentAsync(new string[] { Scope }, app.Users.FirstOrDefault());
177184
}
178185
catch (MsalException ex)
179186
{
@@ -248,7 +255,7 @@ private async void SignIn(object sender = null, RoutedEventArgs args = null)
248255
AuthenticationResult result = null;
249256
try
250257
{
251-
result = await app.AcquireTokenAsync(new string[] { clientId });
258+
result = await app.AcquireTokenAsync(new string[] { Scope });
252259
SignInButton.Content = "Clear Cache";
253260
GetTodoList();
254261
}

TodoListService/TodoListService.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
<VisualStudio>
274274
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
275275
<WebProjectProperties>
276-
<UseIIS>False</UseIIS>
276+
<UseIIS>True</UseIIS>
277277
<AutoAssignPort>True</AutoAssignPort>
278278
<DevelopmentServerPort>9184</DevelopmentServerPort>
279279
<DevelopmentServerVPath>/</DevelopmentServerVPath>

0 commit comments

Comments
 (0)