1 # Copyright (C) 2014 Ipsilon project Contributors, for license see COPYING
3 from __future__ import absolute_import
5 from ipsilon.providers.openid.extensions.common import OpenidExtensionBase
6 from openid.extensions import ax
10 'http://schema.openid.net/namePerson': 'fullname',
11 'http://schema.openid.net/contact/email': 'email',
12 'http://axschema.org/namePerson': 'fullname',
13 'http://axschema.org/namePerson/first': 'firstname',
14 'http://axschema.org/namePerson/last': 'lastname',
15 'http://axschema.org/namePerson/friendly': 'nickname',
16 'http://axschema.org/contact/email': 'email',
17 'http://openid.net/schema/namePerson/first': 'firstname',
18 'http://openid.net/schema/namePerson/last': 'lastname',
19 'http://openid.net/schema/namePerson/friendly': 'nickname',
20 'http://openid.net/schema/gender': 'gender',
21 'http://openid.net/schema/language/pref': 'language',
22 'http://fedoauth.org/openid/schema/GPG/keyid': 'gpg_keyid',
23 'http://fedoauth.org/openid/schema/SSH/key': 'ssh_key',
27 class OpenidExtension(OpenidExtensionBase):
29 def __init__(self, *pargs):
30 super(OpenidExtension, self).__init__('Attribute Exchange')
35 def _resp(self, request, userdata):
36 req = ax.FetchRequest.fromOpenIDRequest(request)
39 resp = ax.FetchResponse(req)
40 for name in req.requested_attributes:
44 resp.addValue(name, userdata[AP_MAP[name]])
46 resp.addValue(name, userdata[name])
47 except Exception: # pylint: disable=broad-except
51 def _display(self, request, userdata):
52 resp = self._resp(request, userdata)
56 for name, value in resp.data.items():
60 data[key] = ', '.join(value if value else [])
63 def _response(self, request, userdata):
64 return self._resp(request, userdata)