Skip to content

Commit 0549d3d

Browse files
authored
Damienbod/2-2-TokenCache small improvements to readme and small code clean up (#411)
* small code clean up * small readme improvements * Remove 2019 text * revert indents
1 parent 7d2d8ed commit 0549d3d

File tree

6 files changed

+15
-32
lines changed

6 files changed

+15
-32
lines changed

2-WebApp-graph-user/2-2-TokenCache/Controllers/HomeController.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics;
4-
using System.Linq;
53
using System.Threading.Tasks;
64
using Microsoft.AspNetCore.Authorization;
7-
using Microsoft.Extensions.Configuration;
85
using Microsoft.Identity.Web;
9-
using System.Net;
10-
using System.Net.Http;
116
using Microsoft.Graph;
127
using Microsoft.AspNetCore.Mvc;
138
using Microsoft.Extensions.Logging;
@@ -26,9 +21,9 @@ public class HomeController : Controller
2621
public HomeController(ILogger<HomeController> logger,
2722
GraphServiceClient graphServiceClient)
2823
{
29-
_logger = logger;
24+
_logger = logger;
3025
_graphServiceClient = graphServiceClient;
31-
}
26+
}
3227

3328
[AuthorizeForScopes(ScopeKeySection = "DownstreamApi:Scopes")]
3429
public async Task<IActionResult> Index()

2-WebApp-graph-user/2-2-TokenCache/Program.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
51
using Microsoft.AspNetCore.Hosting;
6-
using Microsoft.Extensions.Configuration;
72
using Microsoft.Extensions.Hosting;
8-
using Microsoft.Extensions.Logging;
93

104
namespace _2_1_Call_MSGraph
115
{

2-WebApp-graph-user/2-2-TokenCache/README-incremental-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ It leverages the ASP.NET Core OpenID Connect middleware and Microsoft Authentica
2626

2727
To run this sample, you'll need:
2828

29-
- [Visual Studio 2019](https://aka.ms/vsdownload) or just the [.NET Core SDK](https://www.microsoft.com/net/learn/get-started)
29+
- [Visual Studio](https://aka.ms/vsdownload) or just the [.NET Core SDK](https://www.microsoft.com/net/learn/get-started)
3030
- An Internet connection
3131
- A Windows machine (necessary if you want to run the app on Windows)
3232
- An OS X machine (necessary if you want to run the app on Mac)

2-WebApp-graph-user/2-2-TokenCache/README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ It leverages the ASP.NET Core OpenID Connect middleware and Microsoft Authentica
2626

2727
To run this sample, you'll need:
2828

29-
- [Visual Studio 2017](https://aka.ms/vsdownload) or just the [.NET Core SDK](https://www.microsoft.com/net/learn/get-started)
29+
- [Visual Studio](https://aka.ms/vsdownload) or just the [.NET Core SDK](https://www.microsoft.com/net/learn/get-started)
3030
- An Internet connection
3131
- A Windows machine (necessary if you want to run the app on Windows)
3232
- An OS X machine (necessary if you want to run the app on Mac)
@@ -186,15 +186,16 @@ public void ConfigureServices(IServiceCollection services)
186186
{
187187
. . .
188188
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
189-
.AddMicrosoftIdentityWebApp(Configuration)
190-
.EnableTokenAcquisitionToCallDownstreamApi(new string[] { Constants.ScopeUserRead })
191-
.AddDistributedTokenCaches();
189+
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
190+
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
191+
.AddMicrosoftGraph(Configuration.GetSection("DownstreamApi"))
192+
.AddDistributedTokenCaches();
192193

193194
services.AddDistributedSqlServerCache(options =>
194195
{
195-
options.ConnectionString = Configuration.GetConnectionString("TokenCacheDbConnStr");
196-
options.SchemaName = "dbo";
197-
options.TableName = "TokenCache";
196+
options.ConnectionString = Configuration.GetConnectionString("TokenCacheDbConnStr");
197+
options.SchemaName = "dbo";
198+
options.TableName = "TokenCache";
198199
});
199200
```
200201

2-WebApp-graph-user/2-2-TokenCache/Startup.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Authentication;
61
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
72
using Microsoft.Identity.Web;
83
using Microsoft.Identity.Web.UI;
94
using Microsoft.AspNetCore.Authorization;
105
using Microsoft.AspNetCore.Builder;
116
using Microsoft.AspNetCore.Hosting;
12-
using Microsoft.AspNetCore.HttpsPolicy;
137
using Microsoft.AspNetCore.Mvc.Authorization;
148
using Microsoft.Extensions.Configuration;
159
using Microsoft.Extensions.DependencyInjection;
1610
using Microsoft.Extensions.Hosting;
17-
using Microsoft.Graph;
1811
using System.IdentityModel.Tokens.Jwt;
1912

2013
namespace _2_1_Call_MSGraph
@@ -52,10 +45,10 @@ dotnet tool install --global dotnet-sql-cache
5245
*/
5346

5447
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
55-
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
56-
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
57-
.AddMicrosoftGraph(Configuration.GetSection("DownstreamApi"))
58-
.AddDistributedTokenCaches();
48+
.AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
49+
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
50+
.AddMicrosoftGraph(Configuration.GetSection("DownstreamApi"))
51+
.AddDistributedTokenCaches();
5952

6053
services.AddDistributedSqlServerCache(options =>
6154
{
Binary file not shown.

0 commit comments

Comments
 (0)