pallets-eco / flask-security

Quick and simple security for Flask applications
MIT License
1.63k stars 513 forks source link

Challenges with @http_auth_required #861

Closed NexPlex closed 4 years ago

NexPlex commented 4 years ago

I'm trying to use @http_auth_required but it does not seem to accept the password.
curl -u 'me@someaddress.net':'=eers3e^X:7' http://localhost:8080/oauth/token

This line always returns false?

verified = _pwd_context.verify(get_hmac(password), user.password)

The same username and password via json post works fine in the /api/loginuser

What am I doing wrong or missing?


SECURITY_PASSWORD_HASH = 'pbkdf2_sha512'
SECURITY_PASSWORD_SALT = 'kfkladsf-mdfadsy-dfsdf-dfadssaf'

@app.route('/oauth/token')
@http_auth_required
def token():
    """View function for login view."""
    logger.info('Logged in user')
 verified = _pwd_context.verify(get_hmac(password), user.password)

@app.route('/api/loginuser', methods=['POST'])
def login():
    """View function for login view."""
    logger.info('Logged in user')
    return token_login.login_with_token(request, app)

def verify_and_update_password(password, user):
    """Returns ``True`` if the password is valid for the specified user.

    Additionally, the hashed password in the database is updated if the
    hashing algorithm happens to have changed.

    :param password: A plaintext password to verify
    :param user: The user to verify against
    """
    if use_double_hash(user.password):
        verified = _pwd_context.verify(get_hmac(password), user.password)
    else:
        # Try with original password.
        verified = _pwd_context.verify(password, user.password)

    if verified and _pwd_context.needs_update(user.password):
        user.password = hash_password(password)
        _datastore.put(user)
    return verified
NexPlex commented 4 years ago

I found the root cause. my CURL password is =eers3e^X:7 If I view request.authorization.password is =eers3eX:7

Notice the request.authorization.password is missing this character "^" between the e and X.

Any suggestions?

NexPlex commented 4 years ago

I removed the ^ character from the password and @http_auth_required works correctly. Closing this issue

I opened a ticket with flask about this issue.