@@ -18,6 +18,7 @@ public partial class Startup
18
18
public static string AppKey = String . Empty ;
19
19
public static string TodoListResourceId = String . Empty ;
20
20
public static string TodoListBaseAddress = String . Empty ;
21
+ public static string GraphResourceId = String . Empty ;
21
22
22
23
public void ConfigureAuth ( IApplicationBuilder app )
23
24
{
@@ -27,6 +28,7 @@ public void ConfigureAuth(IApplicationBuilder app)
27
28
AppKey = Configuration . Get ( "AzureAd:AppKey" ) ;
28
29
TodoListResourceId = Configuration . Get ( "AzureAd:TodoListResourceId" ) ;
29
30
TodoListBaseAddress = Configuration . Get ( "AzureAd:TodoListBaseAddress" ) ;
31
+ GraphResourceId = Configuration . Get ( "AzureAd:GraphResourceId" ) ;
30
32
31
33
// Configure the Session Middleware, Used for Storing Tokens
32
34
app . UseSession ( ) ;
@@ -47,13 +49,12 @@ public void ConfigureAuth(IApplicationBuilder app)
47
49
48
50
public async Task OnAuthorizationCodeReceived ( AuthorizationCodeReceivedNotification notification )
49
51
{
50
- // Acquire a Token for the TodoList Web API, and Cache it For Later Use
52
+ // Acquire a Token for the Graph API and cache it. In the TodoListController, we'll use the cache to acquire a token to the Todo List API
51
53
string userObjectId = notification . AuthenticationTicket . Principal . FindFirst ( "http://schemas.microsoft.com/identity/claims/objectidentifier" ) . Value ;
52
54
ClientCredential clientCred = new ClientCredential ( ClientId , AppKey ) ;
53
55
AuthenticationContext authContext = new AuthenticationContext ( Authority , new NaiveSessionCache ( userObjectId , notification . HttpContext . Session ) ) ;
54
56
AuthenticationResult authResult = await authContext . AcquireTokenByAuthorizationCodeAsync (
55
- notification . Code , new Uri ( notification . RedirectUri ) , clientCred , Startup . TodoListResourceId ) ;
56
-
57
+ notification . Code , new Uri ( notification . RedirectUri ) , clientCred , Startup . GraphResourceId ) ;
57
58
}
58
59
}
59
60
}
0 commit comments