Flask Login - @login_manager.token_loader not being called
<p>I am trying to use a token to authenticate users.</p>

<p>I have managed to get the process working using:</p>

<pre><code>@login_manager.user_loader
def load_user(userid):
    from models import User
    return User.get(userid)
</code></pre>

<p>However I don't know how to get the process working when using a <code>token</code>.</p>

<p>In my <code>views.py</code> file, I have:</p>

<pre><code>from flask import request, jsonify, url_for, render_template, session

@login_manager.token_loader
def load_token(token):

    # Check token and return user
</code></pre>

<p>When I login a user:</p>

<pre><code>def _do_login_user(user):
    # User must have been authenticated
    if not user: raise_error('user does not exist', 'A user with this email address does not exist', 404)     

    # Check if user account is enabled
    if not user.is_active:
        raise_error('inactive account', 'Your account has not been enabled. Check your email Inbox and Spam folders for the confirmation email', 401)

    # Use Flask-Login to sign in user
    login_user(user)

    return json.dumps({"data":{"success":"true", "message":"You have logged in successfully!"}})
</code></pre>

<p><strong>User Model</strong></p>

<pre><code>class User(db.Model, UserMixin):

    def get_auth_token(self):
        s = Serializer(app.config['SECRET_KEY'], expires_in = 6000)
        return s.dumps({'id': self.id, 'password': self.password})
</code></pre>

<p>At what point should I be calling <code>User.get_auth_token()</code> and should I manually be setting this token in the <code>session</code>?</p>

<p>Finally when does <code>@login_manager.token_loader</code> get called?</p>

<p>Thanks for your help.</p>