def complete(request, on_success=None, on_failure=None, return_to=None, **kwargs): """ complete openid signin """ on_success = on_success or default_on_success on_failure = on_failure or default_on_failure consumer = Consumer(request.session, DjangoOpenIDStore()) # make sure params are encoded in utf8 params = dict((k, smart_unicode(v)) for k, v in request.GET.items()) openid_response = consumer.complete(params, return_to) if openid_response.status == SUCCESS: return on_success(request, openid_response.identity_url, openid_response, **kwargs) elif openid_response.status == CANCEL: return on_failure(request, 'The request was canceled', **kwargs) elif openid_response.status == FAILURE: return on_failure(request, openid_response.message, **kwargs) elif openid_response.status == SETUP_NEEDED: return on_failure(request, 'Setup needed', **kwargs) else: assert False, "Bad openid status: %s" % openid_response.status
def ask_openid(request, openid_url, redirect_to, on_failure=None): on_failure = on_failure or signin_failure sreg_req = None ax_req = None _openid_url = openid_url trust_root = getattr(settings, 'OPENID_TRUST_ROOT', get_url_host(request) + '/') if xri.identifierScheme(openid_url) == 'XRI' and getattr( settings, 'OPENID_DISALLOW_INAMES', False): msg = ("i-names are not supported") auth_oidlogin.send(sender=None, openid_url=_openid_url, state='not_supported') return on_failure(request, msg) consumer = Consumer(request.session, DjangoOpenIDStore()) try: auth_request = consumer.begin(openid_url) except DiscoveryFailure: msg = ("The OpenID %s was invalid") % openid_url auth_oidlogin.send(sender=None, openid_url=_openid_url, state='invalid') return on_failure(request, msg) # get capabilities use_ax, use_sreg = discover_extensions(openid_url) if use_sreg: # set sreg extension # we always ask for nickname and email sreg_attrs = getattr(settings, 'OPENID_SREG', {}) sreg_attrs.update({"optional": ['nickname', 'email']}) sreg_req = sreg.SRegRequest(**sreg_attrs) if use_ax: # set ax extension # we always ask for nickname and email ax_req = ax.FetchRequest() ax_req.add( ax.AttrInfo('http://schema.openid.net/contact/email', alias='email', required=True)) ax_req.add( ax.AttrInfo('http://schema.openid.net/namePerson/friendly', alias='nickname', required=True)) # add custom ax attrs ax_attrs = getattr(settings, 'OPENID_AX', []) for attr in ax_attrs: if len(attr) == 2: ax_req.add(ax.AttrInfo(attr[0], required=alias[1])) else: ax_req.add(ax.AttrInfo(attr[0])) if sreg_req is not None: auth_request.addExtension(sreg_req) if ax_req is not None: auth_request.addExtension(ax_req) redirect_url = auth_request.redirectURL(trust_root, redirect_to) return HttpResponseRedirect(redirect_url)
def mycomplete(request, on_success=None, on_failure=None, return_to=None, **kwargs): on_success = on_success or default_on_success on_failure = on_failure or default_on_failure consumer = Consumer(request.session, DjangoOpenIDStore()) # make sure params are encoded in utf8 params = dict((k, smart_unicode(v)) for k, v in request.GET.items()) openid_response = consumer.complete(params, return_to) if not hasattr(request.GET, 'openid.identity'): _openid_url = 'None' else: _openid_url = request.GET['openid.identity'] if openid_response.status == SUCCESS: auth_oidlogin.send(sender=None, openid_url=_openid_url, state='success') return on_success(request, openid_response.identity_url, openid_response, **kwargs) elif openid_response.status == CANCEL: auth_oidlogin.send(sender=None, openid_url=_openid_url, state='cancel') return on_failure(request, 'The request was canceled', **kwargs) elif openid_response.status == FAILURE: auth_oidlogin.send(sender=None, openid_url=_openid_url, state='failure') return on_failure(request, openid_response.message, **kwargs) elif openid_response.status == SETUP_NEEDED: auth_oidlogin.send(sender=None, openid_url=_openid_url, state='setup_needed') return on_failure(request, 'Setup needed', **kwargs) else: assert False, "Bad openid status: %s" % openid_response.status
def handle_noargs(self, **options): openid = DjangoOpenIDStore() openid.cleanupAssociations()
def handle_noargs(self, **options): openid = DjangoOpenIDStore() openid.cleanupNonces()
def handle_noargs(self, **options): openid = DjangoOpenIDStore() openid.cleanupNonce()