首页 > 解决方案 > Microsoft.Identity.Web 库为带有 Azure Cosmos DB 的 ASP.NET Core 应用程序分布式令牌缓存。我们如何重用缓存的令牌?

问题描述

我从以下网站进行了实施:

https://dev.to/425show/implement-a-distributed-token-cache-for-asp-net-core-apps-with-azure-cosmos-db-23ai

我已经使用这个 NuGet 包来存储令牌:Microsoft.Extensions.Caching.Cosmos

在 startup.cs 文件中添加代码

    services.AddCosmosCache((CosmosCacheOptions cacheOptions) =>
{
    cacheOptions.ContainerName = Configuration["CosmosCacheContainer"];
    cacheOptions.DatabaseName = Configuration["CosmosCacheDatabase"];
    cacheOptions.ClientBuilder = new CosmosClientBuilder(Configuration["CosmosConnectionString"]);
    cacheOptions.CreateIfNotExists = true;
});

services.AddMicrosoftWebAppAuthentication(Configuration)
    .AddMicrosoftWebAppCallsWebApi(Configuration, new string[] { "User.Read", "Mail.Read" })
.AddDistributedTokenCaches();

令牌成功保存在 cosmos DB 中。

现在我有两个问题:

  1. 如何使用此库 Microsoft.Identity.Web 扩展方法获取已存储的令牌?

  2. 令牌到期后如何更新,我们是否需要执行任何额外的活动?

标签: azureasp.net-coretokenmsaldistributed-caching

解决方案


推荐阅读