Skip to content

Do not remove cached credentials when login with wrong password #42

@Adphi

Description

@Adphi

First of all, thanks for this project 😀.
I'm trying to configure an office365 proxy for an old application.
The idea is to configure the proxy once, then use only the cached credentials to run in a headless environment.

I was doing some testing to configure the initial credentials when I found that attempting to log in with an invalid password clears the cached access token and refresh token.

The exception is raised when the decryption fails:

access_token = OAuth2Helper.decrypt(cryptographer, access_token)

and caught as InvalidToken which then deletes the cached credentials instead of sending an unauthorised or invalid crendentials error:

except InvalidToken as e:
# if invalid details are the reason for failure we need to remove our cached version and re-authenticate
config.remove_option(username, 'token_salt')
config.remove_option(username, 'access_token')
config.remove_option(username, 'access_token_expiry')
config.remove_option(username, 'refresh_token')
AppConfig.save()
if recurse_retries:
Log.info('Retrying login due to exception while requesting OAuth 2.0 credentials:', Log.error_string(e))
return OAuth2Helper.get_oauth2_credentials(username, password, connection_info, recurse_retries=False)
except Exception as e:
# note that we don't currently remove cached credentials here, as failures on the initial request are
# before caching happens, and the assumption is that refresh token request exceptions are temporal (e.g.,
# network errors: URLError(OSError(50, 'Network is down'))) rather than e.g., bad requests
Log.info('Caught exception while requesting OAuth 2.0 credentials:', Log.error_string(e))
return False, '%s: Login failure - saved authentication data invalid for account %s' % (
APP_NAME, username)

How could this be handled so that invalid credentials do not logout a legit user ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions