【问题标题】:.Net Core 2 - How to add and use Authentication service (Jwt endpoint).Net Core 2 - 如何添加和使用身份验证服务(Jwt 端点)
【发布时间】:2018-02-03 14:49:30
【问题描述】:

我正在使用 .Net Core 2。我需要添加一个简单的令牌端点。我在关注this的文章却发现下面的方法是obsolete in .Net Core 2

app.UseJwtBearerAuthentication();

引用第二个链接:

Configure(): UseXyzAuthentication() 已被 ConfigureService(): AddXyz() 取代

因此,在 ConfigureService 方法中,我尝试使用类似

services.AddAuthentication(new JwtBearerOptions());

这是不正确的,我知道但如何做到这一点? 不幸的是,我在网上找不到任何帮助。

谢谢

【问题讨论】:

    标签: asp.net-web-api2 owin-middleware .net-core-2.0


    【解决方案1】:

    migration guide 包含一整篇专门讨论身份验证和身份变化的文章:

    Configure,您必须致电app.UseAuthentication();

    ConfigureServices 中的代码应该是:

    services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddJwtBearer(options => {
            options.Audience = "http://localhost:5001/";
            options.Authority = "http://localhost:5000/";
        });
    

    【讨论】:

      【解决方案2】:

      它还可以以更容易和技术性的方式解释。好solution

      【讨论】:

        【解决方案3】:

        这些是在核心 2.0 中以更有效的方式实现的 可能duplicate

        【讨论】:

        • 谢谢,有帮助
        猜你喜欢
        • 2018-03-01
        • 2018-06-22
        • 2023-04-01
        • 2017-07-09
        • 2019-06-24
        • 2020-07-26
        • 2020-10-08
        • 2020-01-30
        • 2019-11-18
        相关资源
        最近更新 更多