Skip to content

Commit dd0d8e1

Browse files
author
Tiago Brenck
committed
Fix issue 158:
To be able to share the SQL token cache between apps, the `DataProtection` must share the same application name.
1 parent 453b55a commit dd0d8e1

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

4-WebApp-your-API/Client/Controllers/TodoListController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.AspNetCore.Http;
22
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Identity.Web.Client;
34
using System.Collections.Generic;
45
using System.Threading.Tasks;
56
using TodoListClient.Services;
@@ -18,6 +19,7 @@ public TodoListController(ITodoListService todoListService)
1819
}
1920

2021
// GET: TodoList
22+
//[MsalUiRequiredExceptionFilter(ScopeKeySection = "TodoList:TodoListScope")]
2123
public async Task<ActionResult> Index()
2224
{
2325
return View(await _todoListService.GetAsync());

Microsoft.Identity.Web/Client/TokenCacheProviders/Sql/MSALAppSqlTokenCacheProviderExtension.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ public static IServiceCollection AddSqlPerUserTokenCache(this IServiceCollection
9090
//var tokenCacheDbContext = new TokenCacheDbContext(tokenCacheDbContextBuilder.Options);
9191
//tokenCacheDbContext.Database.EnsureCreated();
9292

93-
services.AddDataProtection();
93+
// To share protected payloads among apps, configure SetApplicationName in each app with the same value.
94+
// https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-2.2#setapplicationname
95+
services.AddDataProtection()
96+
.SetApplicationName("WebApp_Tutorial");
9497

9598
services.AddDbContext<TokenCacheDbContext>(options =>
9699
options.UseSqlServer(sqlTokenCacheOptions.SqlConnectionString));

0 commit comments

Comments
 (0)