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();

Token 成功保存到 Cosmos DB。

现在我有两个问题:

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

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)