Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove AssignRoles and UnAssignRoles from ServiceStack API

Tags:

servicestack

I'm using the Authentication feature in ServiceStack and configured the Auth plugin to use CredentialsAuthProvider. On the generated metadata page, ServiceStack shows the following operations:

  • Auth
  • AssignRoles
  • UnAssignRoles

I'm only using the Auth operation, why I would like to remove the roles operations to avoid that the readers of this page get confused on how to use the API. Is this possible?

like image 471
ThomasArdal Avatar asked Feb 21 '13 06:02

ThomasArdal


2 Answers

you could do the following which will remove only AssignRoles and UnAssignRoles

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

authFeature.IncludeAssignRoleServices = false; 

Plugins.Add(authFeature);
like image 113
Muhammad Soliman Avatar answered Oct 04 '22 23:10

Muhammad Soliman


When in doubt look to see if there's a description in the Plugins wiki or for this, the dedicated Authentication page.

Each plugin has properties which override it's behavior, in this case just override it with the routes that are available:

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

Which 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 the AuthFeature is also useful to see the defaults of each property.

like image 26
mythz Avatar answered Oct 04 '22 23:10

mythz