Not sure if this or stackoverflow is best place to ask normal questions, bit I’ll try here, let me know if not appropriate.
Having switched to v4, I am also changing the way we do our Roles, particularly trying to use the new UserAuthRole table. However, when I set a role of a newly registered user, it is saved into the Session but not the UserAuth or UserAuthRole tables.
Clearly, I’m missing something fundamental but can’t any find good references for how these should work in a more complicated situations than SocialBootstrapApi.
Can anyone point me at some references or examples showing good uses of UserAuth and UserAuthRole,? Thanks.
Hi Colin, To look at the UserAuthRoles table you would need to modify your CustomAuthUser session like: https://github.com/ServiceStack/ServiceStack/wiki/Release-Notes#wiki-new-optional-userauthrole-table-added
You would need to add the roles manually to your table, e.g:
db.Insert(new UserAuthRole { UserAuthId = userId, Role = “Role” }); //etc
Colin Mackie:
Demis, Thanks. That was my fundamental misunderstaing. I assumed UserAuth was being managed for me
So after the user is added by the registration service, I have to manage all subsequent changes? I guess my issue was not being able to find information around this (back from v3)
Yeah the default behavior is still to blob them, I’ll look at some way to provide an option to save them in those tables instead.
But at the moment you would have to add them to the db yourself. Though it is just adding POCO rows to a OrmLite table.
Colin Mackie:
They aren’t being saved into UserAuth either. During my registration I effectively do
session.Roles.Add(“MyRole”);
which I can see through redis is stored in the session, but not the UserAuth or UserAuthRole. You explained why not for UserAuthRole, but you make it sound like it should have been written into the UserAuth row. Or do I have to update UserAuth from session too?
It saves if you use the AssignRolesService: https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack/Auth/AssignRolesService.cs#L67
Just adding it to the session won’t persist it.
Colin Mackie:
Got it. Thanks.
__________
Hey Colin, I’ve just implemented the 'UseDistinctRoleTables ’ option in OrmLiteAuthRepository, e.g:
container.Register<IAuthRepository>(c =>
new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>()) {
UseDistinctRoleTables = true });
that you can use to enable to Roles and Permissions to be persisted in distinct tables in this commit: https://github.com/ServiceStack/ServiceStack/commit/81d2530804a9d76a6681d9ec14e454b6c0cf7d70
It’s integrated with the rest of ServiceStack so you can re-use the AssignRoles/UnAssignRoles services and you don’t need to do anything else like overriding the custom HasRoles/HasPermissions methods, as it will automatically check those tables if the option is enabled.
It’s just been published to MyGet, feel free to give it a spin: https://github.com/ServiceStack/ServiceStack/wiki/MyGet