微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Microsoft.Identity.Web 库使用 Azure Cosmos DB 为 ASP.NET Core 应用分发令牌缓存我们如何重新使用缓存的令牌?

如何解决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 举报,一经查实,本站将立刻删除。