How to remove AssignRoles and UnAssignRoles from ServiceStack API

I use the authentication function in ServiceStack and have configured the Auth plugin to use CredentialsAuthProvider. On the generated metadata page, ServiceStack displays the following operations:

  • Auth
  • Assignoles
  • Unassignroles

I use only the Auth operation, so I would like to remove role operations in order to avoid confusion among readers of this page on how to use the API. Is it possible?

+7
source share
2 answers

you can do the following which only removes AssignRoles and UnAssignRoles

AuthFeature authFeature = new AuthFeature(() => new AuthUserSession(), new IAuthProvider[] { new BasicAuthProvider() }); authFeature.IncludeAssignRoleServices = false; Plugins.Add(authFeature); 
+16
source

If in doubt, see if there is a description in the Plugins wiki or, for that, a dedicated Authentication Page .

Each plugin has properties that override its behavior, in this case, simply override it with the available routes:

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

This is a short hand for:

 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. } )); 

The source code for AuthFeature is also useful for viewing the default values ​​of each property.

+6
source

All Articles