【发布时间】:2017-11-21 00:30:01
【问题描述】:
我正在尝试让身份服务器的 Asp.Net 身份示例在我的 Web Api 项目中工作,而初学者我正在尝试使用不记名令牌获取令牌并向 API 发送请求。
所以使用提琴手,我可以向https://localhost:44333/core/connect/token 发送一个请求,内容如下:client_id=roclient&client_secret=secret&grant_type=password&username=bob&password=mypass&scope=read write offline_access,它工作正常,我得到了访问令牌和刷新令牌。
然后我的解决方案中有一个 Web Api 项目,其中包含使用不记名令牌的代码:
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "https://localhost:44333",
ValidationMode = ValidationMode.ValidationEndpoint,
RequiredScopes = new[] { "api1" }
});
以及一个使用[Authorize]装饰器保护api的测试控制器。
正如我所说,获取令牌工作正常,但是当我使用提琴手将请求发送到 api 时,我总是得到“401 授权被拒绝......”的事情。
我在提琴手请求中提出的当然是:
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImE...
我做错了吗?
【问题讨论】:
标签: asp.net-identity asp.net-web-api2 thinktecture-ident-server identityserver3 thinktecture