Note that there are some explanatory texts on larger screens.

plurals
  1. POpassport.js local strategy- logging in with username, authenticate later requests with token
    primarykey
    data
    text
    <p>I'm having trouble with passport.js using the local strategy. I have 2 specific problems:</p> <ol> <li>I am not getting persistent sessions to work with example code (see below) for the most basic case. </li> <li>I want to go sessionless. For the most basic case, on login, I'll pass in a username + password that provides me with a session token, on regular requests I'll use this session token hashed with some other stuff to authenticate. Is this easily done with passport? It seems like passport doesn't offer much in this case and that cooking up my own solution is easier- just login/logout with standard checks, and then a middleware that unhashes request tokens to verify requests. Easy cheezy?</li> </ol> <p><strong>Problem 1:</strong></p> <p>Using the reference code from the library:</p> <p><a href="https://github.com/jaredhanson/passport-local/blob/master/examples/login/app.js" rel="nofollow">https://github.com/jaredhanson/passport-local/blob/master/examples/login/app.js</a></p> <p>I do a series of commands to show logged out vs logged in:</p> <p>A. check /account, not logged in</p> <pre><code>curl -v localhost:3000/account </code></pre> <p>As expected I get a redirect to /login</p> <pre><code>&lt;p&gt;Moved Temporarily. Redirecting to &lt;a href="http://localhost:9292/login"&gt;http://localhost:3000/login&lt;/a&gt;&lt;/p&gt; </code></pre> <p>B. login</p> <pre><code>curl -v -d "username=bob&amp;password=secret" http://127.0.0.1:3000/login </code></pre> <p>Also as expected, I get a redirect to /</p> <pre><code>&lt;p&gt;Moved Temporarily. Redirecting to &lt;a href="http://127.0.0.1:3000/"&gt;http://127.0.0.1:3000/&lt;/a&gt;&lt;/p&gt; </code></pre> <p>C. check /account, logged in</p> <pre><code>curl -v localhost:3000/account </code></pre> <p><strong>What the hell???</strong></p> <pre><code>&lt;p&gt;Moved Temporarily. Redirecting to &lt;a href="http://localhost:9292/login"&gt;http://localhost:3000/login&lt;/a&gt;&lt;/p&gt; </code></pre>
    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.
 

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