0

I am wondering if we could modify ServiceStack authentication generated UserAuth, UserAuthDetails etc schema? Need a few more fields to existing UserAuth schema. Thanks.

Isley
  • 197
  • 15

1 Answers1

1

Depending on your UserAuthProvider you can instead specify to use a custom/extended UserAuth when you're registering your UserAuth Repository in your AppHost:

public void Configure(Container container)
{
    //...
    var authRepo = new OrmLiteAuthRepository<CustomUserAuth, UserAuthDetails>(dbFactory);
    container.Register<IUserAuthRepository>(authRepo);
    authRepo.InitSchema();
}

Where CustomUserAuth is your own POCO with additional fields you want to store in the underlying UserAuth RDBMS table, e.g:

public class CustomUserAuth : UserAuth
{
    public string CustomField1 { get; set; }
}

Also see this previous answer for other ways to extend ServiceStack Auth.

Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • Hi, i've read through the "How can I extend ServiceStack Authentication" thread for extending UserAuth table purpose. Can I ask where do i apply this to? userAuth.Set(new Address { ... }); var address = userAuth.Get
    (); I mean, what is this userAuth? Thanks.
    – Isley Oct 26 '15 at 23:35
  • @Isley I've expanded the answer to more info about using your own CustomUserAuth that inherits UserAuth. – mythz Oct 26 '15 at 23:42
  • Thanks a lot. With your instruction, I have figured it out. – Isley Oct 26 '15 at 23:55
  • Sorry, one more problem. When I tried to register into the customized User table, http://localhost:55440/api/json/reply/Register threw 500 error: "ResponseStatus": { "ErrorCode": "InvalidCastException", "Message": "Unable to cast object of type 'ServiceStack.Auth.UserAuth' to type 'SOAMS.Api.ServiceModel.Types.User'.", How can I refer this to User instead of UserAuth? – Isley Oct 27 '15 at 00:50
  • @Isley Open a new question for any new issues/questions. Also avoid dumping stack traces in comments. Since this is different to your original question post the stack trace in a new question, otherwise if it provides more context to your original question, edit the question to post the stacktrace. Also don't forget to mark answers that answer your questions as complete to close the question. – mythz Oct 27 '15 at 01:32