aboutsummaryrefslogtreecommitdiffstats
path: root/cloud_mdir_sync/oauth.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloud_mdir_sync/oauth.py')
-rw-r--r--cloud_mdir_sync/oauth.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/cloud_mdir_sync/oauth.py b/cloud_mdir_sync/oauth.py
index 163dcba..55f3f31 100644
--- a/cloud_mdir_sync/oauth.py
+++ b/cloud_mdir_sync/oauth.py
@@ -1,10 +1,35 @@
# SPDX-License-Identifier: GPL-2.0+
import asyncio
import os
+from abc import abstractmethod
+from typing import TYPE_CHECKING, List
import aiohttp
import aiohttp.web
+if TYPE_CHECKING:
+ from . import config
+
+
+def check_scopes(token, required_scopes: List[str]) -> bool:
+ if token is None:
+ return False
+ tscopes = set(token.get("scope", []))
+ return set(required_scopes).issubset(tscopes)
+
+
+class Account(object):
+ """An OAUTH2 account"""
+ oauth_smtp = False
+
+ def __init__(self, cfg: "config.Config", user: str):
+ self.cfg = cfg
+ self.user = user
+
+ @abstractmethod
+ async def get_xoauth2_bytes(self, proto: str) -> bytes:
+ pass
+
class WebServer(object):
"""A small web server is used to manage oauth requests. The user should point a browser