【发布时间】:2015-09-09 23:32:10
【问题描述】:
我们已经询问并收到了有关如何执行资源所有者密码凭据流程的答复。 Configure the authorization server endpoint我们能够从身份服务器接收访问令牌并将其存储在依赖方的数据存储中。
我们现在需要学习如何在资源服务器上验证访问令牌。
在我们的资源服务器的Startup 中,我们目前有这个:
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication();
}
public void Configure(IApplicationBuilder app)
{
// Add a new middleware validating access tokens issued by the server.
app.UseOAuthBearerAuthentication(options =>
{
options.AutomaticAuthentication = true;
options.Audience = "http://localhost:50000/";
options.Authority = "http://localhost:50000/";
});
app.Run(async (context) =>
{
// this runs on each request not just per application startup
await context.Response.WriteAsync(DateTime.Now.ToString() +
" Hello Resource Owner Password Flow...");
});
}
我们需要在资源服务器中的控制器/操作中添加什么来检查访问令牌验证是否成功?例如。在伪代码中:
public string MyAction()
{
if(AccessTokenIsValid())
{
return "one thing.";
}
else
{
return "another.";
}
}
【问题讨论】:
标签: asp.net openid asp.net-core openid-connect