servicestack - 带有 IdentityServer 的 ServiceStack
问题描述
使用https://github.com/NetCoreTemplates/mvcidentityserver上的模板 并尝试要求授权以访问 ServiceStack“Hello”对象。
我能够检索令牌并调用
https://localhost:5001/servicestack-identity
和
https://localhost:5001/webapi-identity
从 PostMan 成功。
但是,如果我添加一个 Authenticate 属性
namespace MyApp.ServiceInterface
{
public class MyServices : Service
{
[Authenticate]
public object Any(Hello request)
{
return new HelloResponse { Result = $"Hello, {request.Name}!" };
}
对于 MyServices 中的 Any 方法,我无法使用令牌调用 /Hello。
/requiresauth 给出相同的结果
解决方案
我可以通过将以下内容添加到 MyApp.Startup.ConfigureServices()...
services.AddAuthentication("Bearer")
.AddJwtBearer("Bearer", options => {
options.Authority = "https://localhost:5000";
options.RequireHttpsMetadata = false;
options.Audience = "api1";
});
推荐阅读
- angular - ionic 4 中的 HTTP Post 未通过 Web 服务
- c++ - 使用 openCV 编译程序时出现 Collect2 ld 错误
- css - 高度为 100% 的 CSS 网格子元素溢出父元素
- node.js - Ng Serve 返回“对象原型可能只是一个对象或空:未定义类型错误:对象原型可能只是一个对象或空:未定义”
- perl - (Perl)从文件中读取字符串时是否可以插入变量?
- sql - 如何通过 Spring Boot JPA 执行具有 INTERVAL 子句的本机 SQL 查询?
- html - Radio Checked 元素选择 Sass
- javascript - 如何在列表视图上按下按钮时编写发送电子邮件的代码
- javascript - 如何将datatable javaScript数据导出到eccel,不导出隐藏列,但不影响隐藏响应数据?
- python - 使用 Matplotlib.Pyplot 显示非规范化图像会导致多色像素马赛克:为什么?