You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starting from a .NET Core MVC Web app that uses OpenID Connect to sign in users, this chapter of the tutorial shows how to make a call to Microsoft Graph `/me` endpoint on behalf of the signed-in user. This sample additionally provides instructions on how to use Sql Server for caching tokens.
19
+
Starting from a .NET Core MVC Web app that uses OpenID Connect to sign in users, this chapter of the tutorial shows how to make a call to Microsoft Graph `/me` endpoint on behalf of the signed-in user. This sample additionally provides instructions on how to use Sql Server or Redis for caching tokens.
20
20
21
21
It leverages the ASP.NET Core OpenID Connect middleware and Microsoft Authentication Library for .NET (MSAL.NET). The complexities of the library's integration with the ASP.NET Core dependency Injection patterns is encapsulated into the `Microsoft.Identity.Web` library project, which is a part of this tutorial.
22
22
@@ -135,16 +135,17 @@ Note: if you had used the automation to setup your application mentioned in [Ste
135
135
1. Find the app key `Domain` and replace the existing value with your Azure AD tenant name.
136
136
1. Find the app key `ClientSecret` and replace the existing value with the key you saved during the creation of the `WebApp-OpenIDConnect-DotNet-code-v2` app, in the Azure portal.
137
137
138
-
#### In the appsettings.json file, configure a Sql server database for token caching, if you have not already done so:
138
+
#### In the appsettings.json file, configure a Sql server database for token caching:
139
139
140
140
1. In the `TokenCacheDbConnStr` key, provide the Sql server connection string to the database you wish to use for token caching.
141
141
> Note:
142
142
> If you want to test this sample locally with Visual Studio, you might want to use localdb, which is installed with Visual Studio.
143
143
> In that case, use the following connection string:
#### [OPTIONAL] In the appsettings.json file, configure a Redis instance for token caching:
160
+
161
+
1. In the `TokenCacheRedisConnStr` key, provide the Redis domain for your instance or `localhost` if testing on a local Redis database. Replace the value of the `TokenCacheRedisInstaceName` key with the name of your instance.
162
+
> Note:
163
+
> ```XML
164
+
>"ConnectionStrings": {
165
+
> // Rest of strings...
166
+
> "TokenCacheRedisConnStr": "[Replace with your domain like so: <your-domain>.redis.cache.windows.net:6380,password=SomeLongPassword,ssl=True,abortConnect=False or with 'localhost' if running locally]",
167
+
> "TokenCacheRedisInstaceName": "[Replace with your instance name]"
168
+
> },
169
+
> ```
170
+
158
171
- In case you want to deploy your app in Sovereign or national clouds, ensure the `GraphApiUrl` option matches the one you want. By default this is Microsoft Graph in the Azure public cloud
159
172
160
173
```JSon
@@ -179,9 +192,9 @@ Starting from the [previous phase of the tutorial](../../2-WebApp-graph-user/2-1
This sample proposes a distributed SQL token cache. To use it, you'll need to add a reference to the `Microsoft.Extensions.Caching.SqlServer` NuGet package
195
+
This sample can use a distributed SQL token cache. To use it, you'll need to add a reference to the `Microsoft.Extensions.Caching.SqlServer` NuGet package
183
196
184
-
### Update the `Startup.cs` file to enable Token caching using Sql database.
197
+
### Update the `Startup.cs` file to enable Token caching using Sql database
ThissamplealsohasanoptionaldistributedRedistokencache. Touseit, you'll need to add a reference to the `Microsoft.Extensions.Caching.StackExchangeRedis` NuGet package
229
+
230
+
### Update the `Startup.cs` file to enable Token caching using Redis
231
+
232
+
```CSharp
233
+
// Uncomment for Redis configuration. Be sure you DO NOT ADD BOTH an SQL cache and Redis cache
- [UseHttpClientFactorytoimplementresilientHTTPrequests](https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests) used by the Graph custom service
229
256
230
-
231
257
## How to deploy this sample to Azure
232
258
233
259
ThisprojecthasoneWebAppproject. TodeployittotheAzureWebSite, you'll need to:
@@ -243,15 +269,20 @@ This project has one WebApp project. To deploy it to the Azure Web Site, you'll
1. Selectorcreateadatabaseserver, andenterserverlogincredentials. CarefullynotedowntheusernameandpasswordfortheSqlserverasyou'll need it when constructing your Sql conenction string later.
Copy file name to clipboardExpand all lines: 2-WebApp-graph-user/2-2-TokenCache/appsettings.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,7 @@
28
28
"ConnectionStrings": {
29
29
"TokenCacheDbConnStr": "[Enter the Sql server connection string, e.g. Server=MY_SQL_SERVER;Database=MsalTokenCacheDatabase;Trusted_Connection=True;",
30
30
"TokenCacheRedisConnStr": "[Replace with your domain like so: <your-domain>.redis.cache.windows.net:6380,password=SomeLongPassword,ssl=True,abortConnect=False or with 'localhost' if running locally]",
31
-
"TokenCacheRedisInstaceName": "[Replace with your instance name]"
31
+
"TokenCacheRedisInstanceName": "[Replace with your instance name]"
0 commit comments