1. Jannis Leidel
  2. django_openid_provider


Jannis Leidel  committed f78276b

Added AX support with pluggable callback backends.

  • Participants
  • Parent commits 59994a7
  • Branches default

Comments (0)

Files changed (4)

File docs/history.rst

View file
  • Ignore whitespace
 * Fixed landing page view to handle redirect URL GET params correctly.
 * Added setting OPENID_SREG_DATA_CALLBACK setting for custom SREG callback
+* Added AX support, new OPENID_AX_DATA_CALLBACK callback.

File openid_provider/conf.py

View file
  • Ignore whitespace
+                           'openid_provder.utils.get_default_ax_data')

File openid_provider/utils.py

View file
  • Ignore whitespace
 # some code from http://www.djangosnippets.org/snippets/310/ by simon
 # and from examples/djopenid from python-openid-2.2.4
 from openid_provider import conf
-from openid.extensions import sreg
+from openid.extensions import ax, sreg
 from django.core.exceptions import ImproperlyConfigured
 from django.utils.importlib import import_module
         'fullname': request.user.get_full_name(),
+def get_default_ax_data(request, orequest):
+    return {
+        'http://axschema.org/contact/email': request.user.email,
+        'http://axschema.org/namePerson': request.user.get_full_name(),
+        'http://axschema.org/namePerson/friendly': request.user.username,
+        'http://axschema.org/namePerson/first': request.user.first_name,
+        'http://axschema.org/namePerson/last': request.user.last_name,
+    }
 def add_sreg_data(request, orequest, oresponse):
     callback = get_sreg_callback()
     if callback is None or not callable(callback):
     sreg_resp = sreg.SRegResponse.extractResponse(sreg_req, sreg_data)
+def add_ax_data(request, orequest, oresponse):
+    callback = get_ax_callback()
+    if callback is None or not callable(callback):
+        return
+    ax_data = callback(request, orequest)
+    ax_req = ax.FetchRequest.fromOpenIDRequest(orequest)
+    ax_resp = ax.FetchResponse(ax_req)
+    for attr in ax_req.getRequiredAttrs():
+        ax_resp.addValue(attr, ax_data.get(attr))
+    oresponse.addExtension(sreg_resp)
 def get_sreg_callback():
         return import_module_attr(conf.SREG_DATA_CALLBACK)
     except (ImportError, AttributeError):
         return None
+def get_ax_callback():
+    try:
+        return import_module_attr(conf.AX_DATA_CALLBACK)
+    except (ImportError, AttributeError):
+        return None
 def get_store(request):
         store_class = import_module_attr(conf.STORE)

File openid_provider/views.py

View file
  • Ignore whitespace
 from openid.yadis.discover import DiscoveryFailure
 from openid.yadis.constants import YADIS_CONTENT_TYPE
-from openid_provider.utils import add_sreg_data, get_store
+from openid_provider.utils import add_sreg_data, add_ax_data, get_store
 def openid_server(request):
         oresponse = server.handleRequest(orequest)
     if request.user.is_authenticated():
         add_sreg_data(request, orequest, oresponse)
+        add_ax_data(request, orequest, oresponse)
     # Convert a webresponse from the OpenID library in to a Django HttpResponse
     webresponse = server.encodeResponse(oresponse)
     response = HttpResponse(webresponse.body)