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
* Adding a new DistributedTokenCacheProvider
This enables to decouple the serialization itself (done by a.NET Core IDistrributedCache implementation), from the token cache logic (done by the DistributedTokenCacheProvider)
See https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed?view=aspnetcore-2.2#distributed-memory-cache.
```CSharp
// or use a distributed Token Cache by adding
.AddDistributedTokenCaches();
// and then choose your implementation.
// See https://docs.microsoft.com/en-us/aspnet/core/performance/caching/distributed?view=aspnetcore-2.2#distributed-memory-cache
// For instance the distributed in memory cache (not cleaned when you stop the app)
services.AddDistributedMemoryCache()
// Or a Redis cache
services.AddStackExchangeRedisCache(options =>
{
options.Configuration = "localhost";
options.InstanceName = "SampleInstance";
});
// Or even a SQL Server token cache
services.AddDistributedSqlServerCache(options =>
{
options.ConnectionString =
_config["DistCache_ConnectionString"];
options.SchemaName = "dbo";
options.TableName = "TestCache";
});
```
* processing PR feedback
* Add more comments
* Improving the identation
* Updating the README.md with new pictures, and details
about the Distributed token caches
* updating the diagrams
* Renaming DistributedTokenCacheProvider to DistributedTokenCacheAdapter as this is an adapter in this particular case
cc: @bgavrilMS
Copy file name to clipboardExpand all lines: Microsoft.Identity.Web/README.md
+41-4Lines changed: 41 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ to enable them to work with the Microsoft identity platform (formerly named Azur
13
13
14
14
As of today, ASP.NET Core web apps templates (`dot net new mvc -auth`) create web apps that sign in users with the Azure AD v1.0 endpoint (allowing to sign in users with their organizational accounts, also named *Work or school accounts*). This library brings `ServiceCollection` extension methods to be used in the ASP.NET Core web app **Startup.cs** file to enable the web app to sign in users with the Microsoft identity platform (formerly Azure AD v2.0 endpoint), and, optionally enable the web app to call APIs on behalf of the signed-in user.
Note that by default, `AddMicrosoftIdentityPlatformAuthentication` gets the configuration from the "AzureAD" section of the configuration files. It has
88
+
several parameters that you can change.
89
+
90
+
Also the proposed token cache serialization is in memory. you can also use the session cache, or various distributed caches
91
+
87
92
### Web app controller
88
93
89
94
For your web app to call web APIs on behalf of the signed-in user, you'll need to add a parameter of type `ITokenAcquisition` to the constructor of your controller (the `ITokenAcquisition` service will be injected by dependency injection by ASP.NET Core)
@@ -125,7 +130,7 @@ public class HomeController : Controller
125
130
126
131
The controller action is decorated by an attribute `AuthorizeForScopesAttribute` which enables to process the `MsalUiRequiredException` that could be thrown by the service implementing `ITokenAcquisition.GetAccessTokenOnBehalfOfUserAsync` so that the web app interacts with theuser, andaskthemtoconsenttothescopes, orre-sign-inifneeded.
Ifyou're certain that your web API will need some specific scopes, you can optionally pass them as arguments to `AddProtectedApiCallsWebApis`.
213
220
214
221
### Web API controller
@@ -218,7 +225,7 @@ For your web API to call downstream APIs, you'll need to:
218
225
-add (likeinwebapps), aparameteroftype `ITokenAcquisition` totheconstructorofyourcontroller (the `ITokenAcquisition` servicewillbeinjectedbydependencyinjectionbyASP.NETCore)
219
226
-verify, inyourcontrolleractions, thatthetokencontainsthescopesexpectedbytheaction. Forthis, you'll call the `VerifyUserHasAnyAcceptedScope` extension method on the `HttpContext`
@@ -262,6 +269,36 @@ For web apps that calls web apis, and web APIs that call downstream APIs, the co
262
269
| `AddInMemoryTokenCaches` | `TokenCacheProviders.InMemory` |Inmemorytokencacheserialization. Thisimplementationisgreatinsamples. It'salsogoodinproductionapplicationsprovidedyoudon'tmindifthetokencacheislost when the web app is restarted. `AddInMemoryTokenCaches` takes an optional parameter of type `MsalMemoryTokenCacheOptions` that enables you to specify the duration after which the cache entry will expire unless it's used.
0 commit comments