aboutsummaryrefslogtreecommitdiffstats
path: root/cloud_mdir_sync/credsrv.py
diff options
context:
space:
mode:
authorJason Gunthorpe <jgg@mellanox.com>2020-06-19 14:10:28 -0300
committerJason Gunthorpe <jgg@nvidia.com>2020-06-22 20:24:18 -0300
commitc607f4a3cbd9cc4c9611db12bfe175b52de514e1 (patch)
tree7d9772b095b956137cab0f17c8941fff2b33b08c /cloud_mdir_sync/credsrv.py
parent6c7dbe902d8679570ca10f39672d844fa5cb6c50 (diff)
downloadcloud_mdir_sync-c607f4a3cbd9cc4c9611db12bfe175b52de514e1.tar.gz
cloud_mdir_sync-c607f4a3cbd9cc4c9611db12bfe175b52de514e1.tar.bz2
cloud_mdir_sync-c607f4a3cbd9cc4c9611db12bfe175b52de514e1.zip
OAUTH: Add support to get an IMAP OAUTH token
Latest mutt can do this for MS and GMail providers, provide support for getting the right scope and some examples how to set it up. Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Diffstat (limited to 'cloud_mdir_sync/credsrv.py')
-rw-r--r--cloud_mdir_sync/credsrv.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/cloud_mdir_sync/credsrv.py b/cloud_mdir_sync/credsrv.py
index 97357bc..45a032f 100644
--- a/cloud_mdir_sync/credsrv.py
+++ b/cloud_mdir_sync/credsrv.py
@@ -11,18 +11,15 @@ from . import config, oauth
class CredentialServer(object):
"""Serve XOAUTH2 bearer tokens over a unix domain socket. The client
writes the user to obtain a token for and the server responds with the
- token"""
- def __init__(self,
- cfg: config.Config,
- path: str,
- accounts: List[oauth.Account],
- umask=0o600):
+ token. protocols can be IMAP or SMTP"""
+ def __init__(self, cfg: config.Config, path: str,
+ accounts: List[oauth.Account], umask, protocols):
self.cfg = cfg
self.path = os.path.abspath(os.path.expanduser(path))
self.umask = umask
self.accounts = {}
for I in accounts:
- I.oauth_smtp = True
+ I.protocols.update(protocols)
self.accounts[I.user] = I
async def go(self):
@@ -55,10 +52,10 @@ class CredentialServer(object):
f"Credential request {proto!r} {opts} {user!r}")
account = self.accounts.get(user)
- if account is None:
+ if account is None or proto not in account.protocols:
return
- xoauth2 = await account.get_xoauth2_bytes("SMTP")
+ xoauth2 = await account.get_xoauth2_bytes(proto)
if xoauth2 is None:
return
writer.write(xoauth2)