Skip to content

Commit c53aa36

Browse files
author
Tiago Brenck
committed
Included documentation about "Sharing the same Token Cache database between apps"
1 parent dd0d8e1 commit c53aa36

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,19 @@ public void ConfigureServices(IServiceCollection services)
102102
The aforementioned four lines of code are explained below.
103103

104104
1. The first two lines enable MSAL.NET to hook-up to the OpenID Connect events to redeem the authorization code obtained by the ASP.NET Core middleware. After obtaining a token for Microsoft Graph, it saves it into the token cache, for use by the Controllers.
105-
1. The last two lines hook up the Sql server database based token caching solution to MSAL.NET. The Sql based token cache requires a **Connection string** named `TokenCacheDbConnStr` available in the **ConnectionStrings** collections of the **appsettings.json** configuration file.
105+
1. The last two lines hook up the Sql server database based token caching solution to MSAL.NET. The Sql based token cache requires a **Connection string** named `TokenCacheDbConnStr` available in the **ConnectionStrings** collections of the **appsettings.json** configuration file.
106106

107107
The files `MSALAppSqlTokenCacheProvider.cs` and `MSALPerUserSqlTokenCacheProvider` of the `Microsoft.Identity.Web` project contains the app and per-user token cache implementations that use Sql server as the token cache.
108108

109+
### Sharing the same Token Cache database between apps
110+
111+
Since we are using `IDataProtector` to protect the token being persisted on the database, in order to enable it to be used between different apps, `SetApplicationName()` must be configured with the same value for all apps. You can read [more details about IDataProtector here.](https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-2.2#setapplicationname)
112+
113+
```csharp
114+
services.AddDataProtection()
115+
.SetApplicationName("WebApp_Tutorial");
116+
```
117+
109118
## Next steps
110119

111120
- Learn how to enable distributed caches in [token cache serialization](../2.2.%20token%20cache%20serialization)

0 commit comments

Comments
 (0)