如何从ServiceStack API中删除AssignRoles和UnAssignRoles

Tho*_*dal 7 servicestack

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

  • 验证
  • AssignRoles
  • UnAssignRoles

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

Muh*_*man 17

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

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

authFeature.IncludeAssignRoleServices = false; 

Plugins.Add(authFeature);
Run Code Online (Sandbox Code Playgroud)


myt*_*thz 7

如有疑问,请查看插件维基中是否有描述,或者是专用的身份验证页面.

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

Plugins.Add(new AuthFeature(() => new AuthUserSession()) {
    IncludeAssignRoleServices = false
});
Run Code Online (Sandbox Code Playgroud)

这是一个简写:

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.
    }    
));
Run Code Online (Sandbox Code Playgroud)

AuthFeature源代码也可用于查看每个属性的默认值.