Hi
I find SS support Roles and Permission, and i know IUserAuthRepository has a method AssignRoles. But i do not know how to give permission to roles, or their do not have relation?
Could you give me a example to show how to use roles and permission, i know add attributes to dto like this [RequiredRole(“Admin”)], but i do not sure how to assign roles and add permission to one user.
Thank you,WebSudoFeature maybe just a example for deriving IPlugin and IAuthEvents
public class WebSudoFeature : IPlugin, IAuthEvents
{
public void Register(IAppHost appHost)
{
...
var authFeature = appHost.GetPlugin<AuthFeature>();
authFeature.AuthEvents.Add(this);
}
// Add implementations of all `IAuthEvents` handlers
public void OnCreated(IRequest httpReq, IAuthSession session) { ... }
A common UX in some websites is to add an extra layer of protection for super protected functionality by getting users to re-confirm their password verifying it’s still them using the website, common in places like confirming a financial transaction.
WebSudo (by @tvjames) is a new feature similar in spirit requiring users to re-authenticate when accessing Services annotated with the [WebSudoRequired] attribute. To make use of WebSudo, first register the plugin:
Plugins.Add(new WebSudoFeature());
You can then apply WebSudo behavior to existing services by annotating them with [WebSudoRequired]:
[WebSudoRequired]
public class RequiresWebSudoService : Service
{
public object Any(RequiresWebSudo request)
{
return request;
}
}
Once enabled this will throw a 402 Web Sudo Required HTTP Error the first time the service is called:
var requiresWebSudo = new RequiresWebSudo { Name = "test" };
try
{
client.Send<RequiresWebSudoResponse>(requiresWebSudo); //throws
}
catch (WebServiceException)
{
client.Send(authRequest); //re-authenticate
var response = client.Send(requiresWebSudo); //success!
}
Re-authenticating afterwards will allow access to the WebSudo service.