Skip to content

Commit 075752e

Browse files
committed
Add support for falling back to login password as secret
See #271
1 parent 52e7299 commit 075752e

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

emailproxy.config

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,15 @@ documentation = The parameters below control advanced options for the proxy. In
292292
using catch-all accounts or the proxy's `--cache-store` parameter you must manually remove unencrypted secrets from
293293
the local configuration file after the encrypted secret has been created (i.e., this will not be automatic).
294294

295+
- use_login_password_as_client_credentials_secret (default = False): When using the O365 client credentials grant
296+
(CCG) flow, rather than encrypting the client secret (see above), the proxy can be instructed to use the given
297+
IMAP/POP/SMTP login password as the client secret. This approach removes the risk of storing the unencrypted client
298+
secret in the proxy's configuration file, and also means there is no risk of unauthorised account access when using
299+
the O365 CCG flow in conjunction with the proxy's catch-all mode (see below). To enable this option, set
300+
`use_login_password_as_client_credentials_secret` to True. Note that if a `client_secret` value is present in your
301+
account's configuration entry, that value will be used instead of the given IMAP/POP/SMTP login password even if
302+
this option is enabled. To avoid this, remove the entire `client_secret` line from the configuration entry.
303+
295304
- allow_catch_all_accounts (default = False): The default behaviour of the proxy is to require a full separate
296305
configuration file entry for each account. However, when proxying multiple accounts from the same domain it can be
297306
cumbersome to have to create multiple near-identical configuration profiles. To simplify this the proxy supports
@@ -308,4 +317,5 @@ documentation = The parameters below control advanced options for the proxy. In
308317
[emailproxy]
309318
delete_account_token_on_password_error = True
310319
encrypt_client_secret_on_first_use = False
320+
use_login_password_as_client_credentials_secret = False
311321
allow_catch_all_accounts = False

emailproxy.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__author__ = 'Simon Robinson'
77
__copyright__ = 'Copyright (c) 2024 Simon Robinson'
88
__license__ = 'Apache 2.0'
9-
__version__ = '2024-07-29' # ISO 8601 (YYYY-MM-DD)
9+
__version__ = '2024-09-07' # ISO 8601 (YYYY-MM-DD)
1010
__package_version__ = '.'.join([str(int(i)) for i in __version__.split('-')]) # for pyproject.toml usage only
1111

1212
import abc
@@ -1125,6 +1125,11 @@ def get_oauth2_authorisation_tokens(token_url, redirect_uri, client_id, client_s
11251125
params['client_assertion_type'] = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer'
11261126
params['client_assertion'] = jwt_client_assertion
11271127

1128+
# CCG flow can fall back to the login password as the client secret (see GitHub #271 discussion)
1129+
elif oauth2_flow == 'client_credentials' and AppConfig.get_global(
1130+
'use_login_password_as_client_credentials_secret', fallback=False):
1131+
params['client_secret'] = password
1132+
11281133
if oauth2_flow != 'authorization_code':
11291134
del params['code'] # CCG/ROPCG flows have no code, but we need the scope and (for ROPCG) username+password
11301135
params['scope'] = oauth2_scope

0 commit comments

Comments
 (0)