【问题标题】:How to cache AAD B2C SecurityTokens in ASP.NET Core如何在 ASP.NET Core 中缓存 AAD B2C 安全令牌
【发布时间】:2018-11-05 06:07:13
【问题描述】:

在 ASP.NET API 中,我们使用 OpenIdConnectCachingSecurityTokenProvider 将 SecurityTokens 缓存 1 分钟,然后再次刷新。

有没有办法在 ASP.NET Core 中重现这种行为?

【问题讨论】:

  • 您解决了这个问题吗,需要进一步的帮助吗?

标签: azure asp.net-core .net-core azure-active-directory azure-ad-b2c


【解决方案1】:

我刚刚使用Microsoft.AspNetCore.Authentication.JwtBearer 在我的.NET Core 2.0 Web API 下检查JwtBearerOptions。您可以显式配置JwtBearerOptions.ConfigurationManager,它负责从元数据中检索、缓存和刷新配置。这里是sn-p的代码,大家可以参考一下:

public void ConfigureServices(IServiceCollection services)
{
    services.AddAuthentication(options =>
    {
        options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
    }).AddJwtBearer(jwtOptions =>
    {
        jwtOptions.Audience = "{Audience}";
        jwtOptions.Authority = "{Authority}";
        jwtOptions.ConfigurationManager = new ConfigurationManager<OpenIdConnectConfiguration>(
            "https://login.microsoftonline.com/bruceb2c.onmicrosoft.com/v2.0/.well-known/openid-configuration?p={your-signin/signup-policy}",
            new OpenIdConnectConfigurationRetriever())
            {
                RefreshInterval = new TimeSpan(0, 5, 0) //5 minutes
            };
    });

    services.AddMvc();
}

【讨论】:

    猜你喜欢
    • 2012-04-05
    • 2019-04-29
    • 2019-04-11
    • 2014-04-18
    • 2020-11-03
    • 2021-06-03
    • 1970-01-01
    • 2017-05-20
    • 2018-07-03
    相关资源
    最近更新 更多