forked from data-exp-lab/girder_ythub
-
Notifications
You must be signed in to change notification settings - Fork 5
/
verificator.py
37 lines (29 loc) · 981 Bytes
/
verificator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from urllib.parse import urlparse
class Verificator:
key = None
def __init__(self, resource_server=None, key=None, user=None, url=None):
if not (resource_server or url):
raise ValueError("Either 'resource_server' or 'url' must be provided")
self.resource_server = resource_server or urlparse(url).netloc
if not (key or user):
raise ValueError("Either 'key' or 'user' must be provided")
if key:
self.key = key
else:
token = next(
(
t
for t in user.get("otherTokens", [])
if t.get("resource_server") == self.resource_server
),
None,
)
if token:
self.key = token["access_token"]
@property
def headers(self):
return {}
def verify(self):
raise NotImplementedError
def preauth(self, user):
pass