+# -*- coding: utf-8 -*-
+
import re
+from django.utils.encoding import smart_unicode
from django.utils.html import escape
from django.http import get_host
class OpenIdAbstractAuthConsumer(AuthenticationConsumer):
dataype2ax_schema = {
- #'username': 'http://axschema.org/namePerson/friendly',
+ 'username': 'http://axschema.org/namePerson/friendly',
'email': 'http://axschema.org/contact/email',
#'web': 'http://axschema.org/contact/web/default',
#'firstname': 'http://axschema.org/namePerson/first',
sreg_attributes = {
"required": {
"email": "email",
- "nickname": "username"
+ "nickname": "username",
+ "fullname": "real_name"
}
}
def prepare_authentication_request(self, request, redirect_to):
if not redirect_to.startswith('http://') or redirect_to.startswith('https://'):
- redirect_to = get_url_host(request) + redirect_to
+ redirect_to = get_url_host(request) + redirect_to
user_url = self.get_user_url(request)
axr = AXFetchRequest()
for data_type, schema in ax_schema.items():
if isinstance(schema, tuple):
- axr.add(AttrInfo(schema[0], 1, True, schema[1]))
+ axr.add(AttrInfo(schema[0], required=True, alias=schema[1]))
else:
- axr.add(AttrInfo(schema, 1, True, data_type))
+ axr.add(AttrInfo(schema, required=True, alias=data_type))
auth_request.addExtension(axr)
consumer = Consumer(request.session, OsqaOpenIDStore())
query_dict = dict([
- (k.encode('utf8'), v.encode('utf8')) for k, v in request.GET.items()
+ (smart_unicode(k), smart_unicode(v)) for k, v in request.GET.items()
])
#for i in query_dict.items():
if sreg_attrs:
sreg_response = SRegResponse.fromSuccessResponse(openid_response)
- all_attrs = {}
- [all_attrs.update(d) for k,d in sreg_attrs.items() if k != "policy_url"]
+ if sreg_response:
+ all_attrs = {}
+ [all_attrs.update(d) for k,d in sreg_attrs.items() if k != "policy_url"]
- for attr_name, local_name in all_attrs.items():
- if attr_name in sreg_response:
- consumer_data[local_name] = sreg_response[attr_name]
+ for attr_name, local_name in all_attrs.items():
+ if attr_name in sreg_response:
+ consumer_data[local_name] = sreg_response[attr_name]
ax_schema = getattr(self, 'dataype2ax_schema', False)
if ax_schema:
- ax = AXFetchResponse.fromSuccessResponse(openid_response)
+ ax = AXFetchResponse.fromSuccessResponse(openid_response, False)
- axargs = ax.getExtensionArgs()
+ if ax:
+ axargs = ax.getExtensionArgs()
- ax_schema2data_type = dict([(s, t) for t, s in ax_schema.items()])
+ ax_schema2data_type = dict([(s, t) for t, s in ax_schema.items()])
- available_types = dict([
- (ax_schema2data_type[s], re.sub('^type\.', '', n))
- for n, s in axargs.items() if s in ax_schema2data_type
- ])
+ available_types = dict([
+ (ax_schema2data_type[s], re.sub('^type\.', '', n))
+ for n, s in axargs.items() if s in ax_schema2data_type
+ ])
- for t, s in available_types.items():
- if not t in consumer_data:
- consumer_data[t] = axargs["value.%s.1" % s]
+ for t, s in available_types.items():
+ if not t in consumer_data:
+ if axargs.get("value.%s.1" % s, None):
+ consumer_data[t] = axargs["value.%s.1" % s]
request.session['auth_consumer_data'] = consumer_data