【问题标题】:Why does using ServiceStack JwtAuthProviderReader add auth endpoints to my resource API?为什么使用 ServiceStack JwtAuthProviderReader 会将身份验证端点添加到我的资源 API?
【发布时间】:2017-11-17 08:54:01
【问题描述】:

我已经设置了一个颁发 JWT 令牌的身份验证服务器。

我现在已经设置了我的第一个资源服务,它将使用请求中提供的不记名令牌进行身份验证/授权。这个服务不是我的认证服务器,它是一个资源服务器。

我将 ServiceStack JwtAuthProviderReader 添加到我的资源服务中:

Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new IAuthProvider[] {
    new JwtAuthProviderReader() {
        HashAlgorithm = "HS256",
        AuthKeyBase64 = AuthSettings.JwtAuthKeyBase64
    },
}));

为什么我的资源服务器现在拥有所有身份验证服务器端点,我使用的是JwtAuthProviderReader,而不是我的身份验证服务使用的JwtAuthProviderAs the documentation states,我的资源服务只是验证令牌。

【问题讨论】:

    标签: servicestack


    【解决方案1】:

    这些不仅限于 JWT AuthProvider,它们是 ServiceStack 的内置 Auth 服务,用于处理任何 ServiceStack 身份验证,即在注册 ServiceStack 的 AuthFeature 插件时。

    如果您没有使用分配/取消分配角色服务,可以通过以下方式禁用它们:

    Plugins.Add(new AuthFeature(...) {
        IncludeAssignRoleServices = false
    });
    

    您还可以通过 AppHost 的构造函数中的dynamically adding Exclude attributes 隐藏服务,使其不显示在元数据页面和服务中,例如:

    public AppHost() : base("MyApp", typeof(MyServices).Assembly)
    {
        typeof(Authenticate)
            .AddAttributes(new ExcludeAttribute(Feature.Metadata));
    }
    

    相当于在Request DTO上添加属性,例如:

    [Exclude(Feature.Metadata)]
    public class Authenticate { ... }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-05
      相关资源
      最近更新 更多