Skip to content

Commit d9d046b

Browse files
committed
Update dsFunc.py
1 parent 3a773ff commit d9d046b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

dsFunc.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
import datetime
22
import time
3+
import requests
4+
5+
6+
def auth(email, password, baseURL, verify):
7+
"""Authenticate the user to the DSpace API."""
8+
data = {'email': email, 'password': password}
9+
header = {'content-type': 'application/json',
10+
'accept': 'application/json'}
11+
session = requests.post(baseURL + '/rest/login', headers=header,
12+
verify=verify,
13+
params=data).cookies['JSESSIONID']
14+
cookies = {'JSESSIONID': session}
15+
return(cookies, header)
16+
17+
18+
def authConfirm(cookies, baseURL, header, verify):
19+
"""Confirm user was successfully authenticated to the DSpace API."""
20+
status = requests.get(baseURL + '/rest/status', headers=header,
21+
cookies=cookies, verify=verify).json()
22+
uName = status['fullname']
23+
authEmail = status['email']
24+
print('authenticated', uName, authEmail)
25+
return(uName, authEmail)
326

427

528
def elapsedTime(startTime, label):

0 commit comments

Comments
 (0)