@@ -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 }
0 commit comments