-
-
Notifications
You must be signed in to change notification settings - Fork 128
Description
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:
email-oauth2-proxy/emailproxy.py
Line 335 in 89f2f7c
| 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:
email-oauth2-proxy/emailproxy.py
Lines 342 to 360 in 89f2f7c
| 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 ?