我應該能夠使用以下內容。services.AddAuthentication()
??.AddIdentityServerJwt();這不起作用,因為AddIdentityServerJwt似乎不存在。另外,我不確定此時此刻我是否想與 IdentityServer 攜手并進。在以前的版本中,我會聲明一個默認方案并在 Startup.cs 文件中配置令牌驗證。然而現在,似乎所有的奶酪都被轉移到了 Core 3 中。我應該如何使用 JWT 配置(盡可能簡單的)安全性并(最好)避免 Identity Server?public void ConfigureServices(IServiceCollection services){? ...? services.AddAuthentication();}public void Configure(IApplicationBuilder app, IWebHostEnvironment env){? ...? //app.UseRouting();? app.UseAuthentication();? //app.UseAuthorization();? //app.UseEndpoints(e => e.MapControllers());}這會在 Swagger 中產生以下錯誤的不同變體。未指定authenticationScheme,并且未找到DefaultChallengeScheme。
1 回答

人到中年有點甜
TA貢獻1895條經驗 獲得超7個贊
缺少的部分是,在調用 后AddAuthentication
,您還需要顯式“選擇”加入 JWT 承載:
public?void?ConfigureServices(IServiceCollection?services){ ??... ??services ????.AddAuthentication() ????.AddJwtBearer(); }
目前,該操作需要手動安裝擴展方法,如[此處](Install-Package Microsoft.AspNetCore.Authentication.JwtBearer -Version 3.0.0-preview6.19307.2)。
安裝包 Microsoft.AspNetCore.Authentication.JwtBearer -版本 3.0.0-preview6.19307.2
Core 3.0 涵蓋該方法的文檔目前重定向到 Core 2.2 的對應文檔,并且由于預覽狀態,可能會隨時更新或刪除。
- 1 回答
- 0 關注
- 173 瀏覽
添加回答
舉報
0/150
提交
取消