Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my answer so far. It works and I can do what I am trying to do, but I would love to hear from some of the Service Stack guys as to whether this is the best way to go about this.</p> <p><strong>To Save custom meta data</strong></p> <p>Create a new class that subclasses the <code>OrmLiteAuthRepository</code>. In my case I just want to use Service Stack's built in Sql database persistence and have it create the tables needed.</p> <p>Re-implement the CreateUserAuth method to save any custom metadata :</p> <pre class="lang-cs prettyprint-override"><code> public UserAuth CreateUserAuth(UserAuth newUser, string password) { newUser.Set(new AccountStatus { IsActive = false, PasswordNeedsReset = true }); return base.CreateUserAuth(newUser, password); } </code></pre> <p><strong>Fetching custom meta data</strong></p> <p>Create a new class that subclasses the CredentialsAuthProvider. Override the Authenticate method.</p> <pre class="lang-cs prettyprint-override"><code> public override object Authenticate(IServiceBase authService, IAuthSession session, Auth request) { var userAuthRepo = authService.ResolveService&lt;IUserAuthRepository&gt;(); var userAuth = userAuthRepo.GetUserAuthByUserName(request.UserName); var accountStatus= userAuth.Get&lt;AccountStatus&gt;(); if (!accountStatus.IsActive) { throw new InvalidOperationException(string.Format("User {0} is not activated.", request.UserName)); } if (!accountStatus.PasswordNeedsReset) { throw new InvalidOperationException("Your password needs to be reset before you can login."); } var authResponse = (AuthResponse)base.Authenticate(authService, session, request); return authResponse; } </code></pre> <p>When an authentication request comes into this method, fetch the UserAuth and the custom meta data. If the user is inactive, or their password needs to be reset throw an InvalidOperationException with an error message.</p> <p>In my client application's Login controller I can check the error message coming back from the service and redirect the user to some page saying there account isn't active yet, or their password needs to be reset before they can be authenticated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload