@@ -25,48 +25,38 @@ def servicex_adaptor_factory(c: ConfigView):
25
25
endpoint = c ['api_endpoint' ]['endpoint' ].as_str_expanded ()
26
26
27
27
# We can default these to "None"
28
- email = c ['api_endpoint' ]['email' ].get (str ) if 'email' in c ['api_endpoint' ] else None
29
- password = c ['api_endpoint' ]['password' ].get (str ) if 'password' in c ['api_endpoint' ] else None
30
- return ServiceXAdaptor (endpoint , email , password )
28
+ refresh_token = c ['api_endpoint' ]['token' ].get (str ) if 'token' in c ['api_endpoint' ] else None
29
+ return ServiceXAdaptor (endpoint , refresh_token )
31
30
32
31
33
32
# Low level routines for interacting with a ServiceX instance via the WebAPI
34
33
class ServiceXAdaptor :
35
- def __init__ (self , endpoint , email = None , password = None ):
34
+ def __init__ (self , endpoint , refresh_token = None ):
36
35
'''
37
36
Authenticated access to ServiceX
38
37
'''
39
38
self ._endpoint = endpoint
40
- self ._email = email
41
- self ._password = password
42
-
43
39
self ._token = None
44
- self ._refresh_token = None
45
-
46
- async def _login (self , client : aiohttp .ClientSession ):
47
- url = f'{ self ._endpoint } /login'
48
- async with client .post (url , json = {
49
- 'email' : self ._email ,
50
- 'password' : self ._password
51
- }) as response :
40
+ self ._refresh_token = refresh_token
41
+
42
+ async def _get_token (self , client : aiohttp .ClientSession ):
43
+ url = f'{ self ._endpoint } /token/refresh'
44
+ headers = {'Authorization' : f'Bearer { self ._refresh_token } ' }
45
+ async with client .post (url , headers = headers ) as response :
52
46
status = response .status
53
47
if status == 200 :
54
48
j = await response .json ()
55
49
self ._token = j ['access_token' ]
56
- self ._refresh_token = j ['refresh_token' ]
57
50
else :
58
51
raise ServiceXException (f'ServiceX login request rejected: { status } ' )
59
52
60
53
async def _get_authorization (self , client : aiohttp .ClientSession ):
61
- if self ._email :
62
- now = datetime .utcnow ().timestamp ()
63
- if not self ._token or jwt .decode (self ._token , verify = False )['exp' ] - now < 0 :
64
- await self ._login (client )
65
- return {
66
- 'Authorization' : f'Bearer { self ._token } '
67
- }
68
- else :
69
- return {}
54
+ now = datetime .utcnow ().timestamp ()
55
+ if not self ._token or jwt .decode (self ._token , verify = False )['exp' ] - now < 0 :
56
+ await self ._get_token (client )
57
+ return {
58
+ 'Authorization' : f'Bearer { self ._token } '
59
+ }
70
60
71
61
async def submit_query (self , client : aiohttp .ClientSession ,
72
62
json_query : Dict [str , str ]) -> Dict [str , str ]:
0 commit comments