Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have not tested this but I think it should get you started. Gladly stand corrected on any of my steps.</p> <p>Things I think you will need to do..</p> <ul> <li>In order to Authenticate against both 'systems' you'll need to set the Forms cookie and save your ServiceStack session. </li> </ul> <p>Instead of calling <code>FormsAuthentication.Authentiate()</code> do something like below. This won't work until you complete all the steps.</p> <pre><code>var apiAuthService = AppHostBase.Resolve&lt;AuthService&gt;(); apiAuthService.RequestContext = System.Web.HttpContext.Current.ToRequestContext(); var apiResponse = apiAuthService.Authenticate(new Auth { UserName = model.UserName, Password = model.Password, RememberMe = false }); </code></pre> <ul> <li>Create a subclass of <code>IUserAuthRepository</code> (for retrieving membership/user/roles from aspnet_* tables and filling ServiceStack AuthUser).</li> </ul> <p>CustomAuthRepository.cs (incomplete, but should get you started)</p> <pre><code>public class CustomAuthRepository : IUserAuthRepository { private readonly MembershipProvider _membershipProvider; private readonly RoleProvider _roleProvider; public CustomAuthRepository() { _membershipProvider = Membership.Provider; _roleProvider = Roles.Provider; } public UserAuth GetUserAuthByUserName(string userNameOrEmail) { var user = _membershipProvider.GetUser(userNameOrEmail, true); return new UserAuth {FirstName = user.UserName, Roles = _roleProvider.GetRolesForUser(userNameOrEmail).ToList() //FILL IN REST OF PROPERTIES}; } public bool TryAuthenticate(string userName, string password, out UserAuth userAuth) { //userId = null; userAuth = GetUserAuthByUserName(userName); if (userAuth == null) return false; if (FormsAuthentication.Authenticate(userName, password)) { FormsAuthentication.SetAuthCookie(userName, false); return true; } userAuth = null; return false; } //MORE METHODS TO IMPLEMENT... } </code></pre> <ul> <li><p>Wire Authentication up for ServiceStack in AppHost configure method. </p> <pre><code>var userRep = new CustomAuthRepository(); container.Register&lt;IUserAuthRepository&gt;(userRep); Plugins.Add( new AuthFeature(() =&gt; new AuthUserSession(), new IAuthProvider[] { new CredentialsAuthProvider() } )); </code></pre></li> </ul>
    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. 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.
 

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