Remap auth tables and fields

Hi all, in my app, in AppHost I initialize the auth db schema using authRepo.InitSchema(); everything works well, but I would like to know if there is a way to remap/change the names of these tables and fields.

Thank you very much for your help.

I’m assuming you’re referring to an OrmLiteAuthRepository in which case you can use ServiceStack’s runtime attribute feature to add attributes at runtime, e.g:

typeof(UserAuth)
    .AddAttributes(new AliasAttribute("NewParentAuth"));
typeof(UserAuthDetails)
    .AddAttributes(new AliasAttribute("NewChildAuth"));

You’ll want to register the attributes at the start before the tables are used

You can also use Custom Auth Tables to use extend the existing UserAuth tables with your own Custom User tables, e.g:

container.Register<IAuthRepository>(c => 
    new OrmLiteAuthRepository<CustomUser, CustomUserDetails>(
        c.Resolve<IDbConnectionFactory>()));

Hi mythz, thank you for your answer!
Using:

typeof(UserAuth)
        .AddAttributes(new AliasAttribute("myUserAuth"));
typeof(UserAuthDetails)
        .AddAttributes(new AliasAttribute("myUserAuthDetails"));
typeof(UserAuthRole)
       .AddAttributes(new AliasAttribute("myUserAuthRole"));

I was able to rename the default Auth Tables names with mine, but I can’t undestand how to rename/delete the fields inside… I’m pretty confused about how things should work.

I’d need to remove many fields from the UserAuth and UserAuthDetails tables that I don’t need and then rename the remaining ones.
To get this… Do I need to redefine the UserAuth and UserAuthDetails with my POCOs like this…

container.Register<IAuthRepository>(new OrmLiteAuthRepository<CustomUser, CustomUserDetails>(Resolve<IDbConnectionFactory>()));

…or I’m completly wrong? because I’ve tried to define my CutomUser and CustomUserDetails classes like this:

    public class CustomUser
    {
        public int Id { get; set; }
        public string UserName { get; set; }
        public string DisplayName { get; set; }
        public string Email { get; set; }
        public string PasswordHash { get; set; }
    }

    public class CustomUserDetails
    {
        public int Id { get; set; }
        public string UserName { get; set; }
        public string Address { get; set; }
        public string City { get; set; }
        public string State { get; set; }
        public string Country { get; set; }
    }

but I get these two errors:

The type 'testauth.ServiceModel.CustomUser' cannot be used as type parameter 'TUserAuth' in the generic type or method 'ServiceStack.Auth.OrmLiteAuthRepository<TUserAuth,TUserAuthDetails>'. There is no implicit reference conversion from 'testauth.ServiceModel.CustomUser' to 'ServiceStack.Auth.IUserAuth'.

The type 'testauth.ServiceModel.CustomUserDetails' cannot be used as type parameter 'TUserAuthDetails' in the generic type or method 'ServiceStack.Auth.OrmLiteAuthRepository<TUserAuth,TUserAuthDetails>'. There is no implicit reference conversion from 'testauth.ServiceModel.CustomUserDetails' to 'ServiceStack.Auth.IUserAuthDetails'.	

I’m following your SocialBootstrap example as reference but I can’t understand where I’m wrong.

ServiceStack needs to understand the schema in order to be able to use it, so you can’t replace it with completely new Types as then it wouldn’t be able to work. At a minimum it needs to at least implement IUserAuth and IUserAuthDetails but it’s generally recommended to inherit UserAuth and UserAuthDetails.

So, from what I can understand I should leave all the schema as it is?
Ok… I think I could do it but is there a way to at least remap the fields names?

The other way to extend UserAuth is to leave these tables as they are and instead link to your own Custom tables using the RefId/RefIdStr fields as mentioned in Linking referential data with RefId and RefIdStr fields - this is what the SocialBootstrap Api example does.

You can rename columns using the same approach by adding attributes at runtime, e.g:

typeof(UserAuth)
    .GetProperty("LastName")
    .AddAttributes(new AliasAttribute("Surname"));

Ok! thank you very much!
For now I think I will just rename the fields!