如何从ServiceStack API中删除AssignRoles和UnAssignRoles

时间:2013-02-21 06:47:41

标签: servicestack

我在ServiceStack中使用身份验证功能,并将Auth插件配置为使用CredentialsAuthProvider。在生成的元数据页面上,ServiceStack显示以下操作:

  • 验证
  • AssignRoles
  • UnAssignRoles

我只使用Auth操作,为什么我要删除角色操作以避免此页面的读者对如何使用API​​感到困惑。这可能吗?

2 个答案:

答案 0 :(得分:17)

您可以执行以下操作,仅删除AssignRoles和UnAssignRoles

AuthFeature authFeature = new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] { new BasicAuthProvider() });

authFeature.IncludeAssignRoleServices = false; 

Plugins.Add(authFeature);

答案 1 :(得分:7)

如有疑问,请查看Plugins wiki中的说明或专有Authentication page

每个插件都有覆盖其行为的属性,在这种情况下只需使用可用的路由覆盖它:

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

这是一个简写:

Plugins.Add(new AuthFeature(() => new AuthUserSession(),
    new IAuthProvider[] { ... },
    ServiceRoutes = new Dictionary<Type, string[]> {
      { typeof(AuthService), new[]{"/auth", "/auth/{provider}"} },
      //Omit the Un/AssignRoles service definitions here.
    }    
));

source code for the AuthFeature对于查看每个属性的默认值也很有用。

相关问题