从 .netcore2.2 升级到 .netcore3.1 后 JWT 身份验证停止工作
JWT authentication stops working after upgrading from .netcore2.2 to .netcore3.1
升级后,
在 Swagger 中 UI 我可以创建不记名令牌,但当我尝试使用它时收到 401。
在错误日志中我看到了
AuthenticationScheme: "Bearer" was not authenticated
和
"POST" requests are not supported
和
Request successfully matched the route with name 'null' and template
2020-09-01 04:58:25.004 +10:00 [Information] [Microsoft.AspNetCore.Hosting.Diagnostics] [{ Id: 1 }] Request starting HTTP/2.0 POST https://localhost:44348/api/job-management/get-user-counts application/json 18
2020-09-01 04:58:25.005 +10:00 [Debug] [Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler] [{ Id: 9, Name: "AuthenticationSchemeNotAuthenticated" }] AuthenticationScheme: "Bearer" was not authenticated.
2020-09-01 04:58:25.005 +10:00 [Debug] [Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware] [{ Id: 1, Name: "MethodNotSupported" }] "POST" requests are not supported
2020-09-01 04:58:25.005 +10:00 [Debug] [Microsoft.AspNetCore.Rewrite.RewriteMiddleware] [{ Id: 1, Name: "RequestContinueResults" }] Request is continuing in applying rules. Current url is "https://localhost:44348/api/job-management/get-user-counts"
2020-09-01 04:58:25.006 +10:00 [Debug] [Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware] [{ Id: 1, Name: "MethodNotSupported" }] "POST" requests are not supported
2020-09-01 04:58:25.006 +10:00 [Debug] [Microsoft.AspNetCore.Routing.Tree.TreeRouter] [{ Id: 1, Name: "RequestMatchedRoute" }] Request successfully matched the route with name 'null' and template '"api/job-management/get-user-counts"'
我想用 VS2019 生成一个新样本 api,但是我找不到 JWT
我在ConfigureServices中添加了
services.AddMvc(option => option.EnableEndpointRouting = false);
我应该如何解决我的问题?
[更新]
我已经查看了 Microsoft 升级指南,但没有发现遗漏任何内容。
我在
找到了答案
我已经正确转换为使用 OpenApiParameter 但我错过了
Schema = new OpenApiSchema() { Type = "String" }
我认为我的问题不是重复的,因为我得到的错误可能会帮助其他人找到答案。
升级后,
在 Swagger 中 UI 我可以创建不记名令牌,但当我尝试使用它时收到 401。
在错误日志中我看到了
AuthenticationScheme: "Bearer" was not authenticated
和
"POST" requests are not supported
和
Request successfully matched the route with name 'null' and template
2020-09-01 04:58:25.004 +10:00 [Information] [Microsoft.AspNetCore.Hosting.Diagnostics] [{ Id: 1 }] Request starting HTTP/2.0 POST https://localhost:44348/api/job-management/get-user-counts application/json 18
2020-09-01 04:58:25.005 +10:00 [Debug] [Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler] [{ Id: 9, Name: "AuthenticationSchemeNotAuthenticated" }] AuthenticationScheme: "Bearer" was not authenticated.
2020-09-01 04:58:25.005 +10:00 [Debug] [Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware] [{ Id: 1, Name: "MethodNotSupported" }] "POST" requests are not supported
2020-09-01 04:58:25.005 +10:00 [Debug] [Microsoft.AspNetCore.Rewrite.RewriteMiddleware] [{ Id: 1, Name: "RequestContinueResults" }] Request is continuing in applying rules. Current url is "https://localhost:44348/api/job-management/get-user-counts"
2020-09-01 04:58:25.006 +10:00 [Debug] [Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware] [{ Id: 1, Name: "MethodNotSupported" }] "POST" requests are not supported
2020-09-01 04:58:25.006 +10:00 [Debug] [Microsoft.AspNetCore.Routing.Tree.TreeRouter] [{ Id: 1, Name: "RequestMatchedRoute" }] Request successfully matched the route with name 'null' and template '"api/job-management/get-user-counts"'
我想用 VS2019 生成一个新样本 api,但是我找不到 JWT
我在ConfigureServices中添加了
services.AddMvc(option => option.EnableEndpointRouting = false);
我应该如何解决我的问题?
[更新]
我已经查看了 Microsoft 升级指南,但没有发现遗漏任何内容。
我在
我已经正确转换为使用 OpenApiParameter 但我错过了
Schema = new OpenApiSchema() { Type = "String" }
我认为我的问题不是重复的,因为我得到的错误可能会帮助其他人找到答案。