forked from steveandroulakis/mytardis-app-auth-aaf
/
utils.py
33 lines (23 loc) · 883 Bytes
/
utils.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
import urllib
import urllib2
from tardis.tardis_portal.auth.authservice import AuthService
auth_key = 'aaf'
def authenticate(username, first_name, last_name, email):
#todo take attr array
user_dict = {'id': username,
'first_name': first_name,
'last_name': last_name or '(none)',
'email': email}
auth_service = AuthService()
user = auth_service._get_or_create_user_from_dict(
user_dict, auth_key)
user.backend = 'django.contrib.auth.backends.ModelBackend'
return user
def request_aaf_info(url, code, state):
url_values = urllib.urlencode({'code': code, 'state': state})
full_url = url + '?' + url_values
response = urllib2.urlopen(full_url)
aaf_attr_json = response.read()
return aaf_attr_json
def get_username_from_aaf_email(mail):
return '__'.join(mail.split("@"))