Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I figured I need to include also the CredentialsAuthProvider in the AuthFeature, which will expose /auth/credentials service which I form post a form to.</p> <pre><code> //this inherits the BasicAuthProvider and is used to authenticate the REST API calls var myCustomAuthProvider = new CustomAuthProvider(appSettings); var credentialsProvider = new CredentialsAuthProvider(appSettings); container.Register&lt;IAuthProvider&gt;(myCustomAuthProvider); container.Register&lt;CredentialsAuthProvider&gt;(credentialsProvider); var authFeature = new AuthFeature(() =&gt; new EnshareSession(new MongoTenantRepository()), new IAuthProvider[] { myCustomAuthProvider, credentialsProvider }) </code></pre> <p>So I specified the action in my login form as /auth/credentials, while providing the required UserName and Password fields. </p> <pre><code> &lt;form action="/auth/credentials" method="post"&gt; &lt;p class="entryfield"&gt; @Html.LabelFor(m =&gt; m.UserName, "Login name:") @Html.TextBoxFor(u =&gt; u.UserName) &lt;/p&gt; &lt;p class="entryfield"&gt; @Html.LabelFor(m =&gt; m.Password) @Html.PasswordFor(m =&gt; m.Password) &lt;/p&gt; &lt;input class="formbutton" type="submit" value="Login" /&gt; &lt;/form&gt; </code></pre> <p>When the form is posted, it hits the authentication code flows properly (<code>TryAuthenticate</code> is called in my <code>IUserAuthRepository</code> and returns true). </p> <p>Ultimately the request receives a 302 and my login form at /login is redisplayed.</p> <pre><code> HTTP/1.1 302 Found Server: ASP.NET Development Server/10.0.0.0 Date: Wed, 30 Oct 2013 08:15:54 GMT X-AspNet-Version: 4.0.30319 X-Powered-By: ServiceStack/3,969 Win32NT/.NET Location: http://localhost:64944/login?redirect=%2fadmin Set-Cookie: X-UAId=3; expires=Sun, 30-Oct-2033 08:15:54 GMT; path=/; HttpOnly </code></pre> <p>It is setting the session cookie (X-AUId) and the user is properly authenticated. Subsequent web browser requests to Services decorated with the Authenticate attribute succeed.</p> <p>So the only missing part is how to ensure that the user is properly redirected after posting to <code>/auth/credentials</code>.</p> <p>To ensure the redirection works, a quick look at the has shown that a Continue parameter is expected.</p> <p>So this is how the login form needs to look like (I reused the Auth class from ServiceStack for the model):</p> <pre><code> @inherits ViewPage&lt;ServiceStack.ServiceInterface.Auth.Auth&gt; @{ Layout = "AdminLayout"; } &lt;form action="/auth/credentials" method="post"&gt; &lt;p class="entryfield"&gt; @Html.LabelFor(m =&gt; m.UserName, "Login name:") @Html.TextBoxFor(u =&gt; u.UserName) &lt;/p&gt; &lt;p class="entryfield"&gt; @Html.LabelFor(m =&gt; m.Password) @Html.PasswordFor(m =&gt; m.Password) &lt;/p&gt; @Html.HiddenFor(m =&gt; m.Continue) &lt;input type="submit" value="Login" /&gt; &lt;/form&gt; </code></pre> <p>The Continue property is populated in the service from the Redirect property of its model.</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.
    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