OpenID Connect 隐式流 - 资源服务器

OpenID Connect Implicit Flow - Resource Server

我已经开始使用 OpenID Connect 隐式流程实施 - 我已经在基于浏览器的 javascript 应用程序中检索了我的访问令牌和 ID 令牌,现在我需要保护我 ASP.NET Core Web API 因此只能通过具有特定声明的用户的有效访问令牌访问它。

我使用什么中间件来验证令牌并确定用户及其声明,以便我可以允许或拒绝他们访问他们请求的资源?

我看过 OpenIdConnectAuthentication 中间件,但是我看到的唯一实现示例使用 "Cookies" 的 SignInScheme,而不是我的 js 应用程序提供的 Bearer 令牌。

谢谢

What middleware do I use to validate the token(s) and determine the user and their claims so I can then allow or deny them access to the resource they are requesting?

如果你的授权服务器颁发JWT令牌,你可以使用ASP.NET团队开发的JWT承载中间件:https://github.com/aspnet/Security/tree/dev/src/Microsoft.AspNetCore.Authentication.JwtBearer.

app.UseJwtBearerAuthentication(new JwtBearerOptions {
    Authority = Configuration["jwt:authority"],
    Audience = Configuration["jwt:audience"]
});

您可以在此处找到样本:https://github.com/aspnet/Security/tree/dev/samples/JwtBearerSample