def __init__(self, openid_, issued, attrs=None, sreg_=None): logging.debug('init janrain openid object') self.openid = openid_ self.issued = issued self.attrs = attrs or {} self.sreg = sreg_ or {} self.is_iname = (xri.identifierScheme(openid_) == 'XRI')
def ask_openid( request, openid_url, redirect_to, on_failure=None, sreg_request=None ): """ basic function to ask openid and return response """ on_failure = on_failure or signin_failure 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") logging.debug('openid failed because i-names are not supported') return on_failure(request, msg) consumer = Consumer(request.session, util.DjangoOpenIDStore()) try: auth_request = consumer.begin(openid_url) except DiscoveryFailure: msg = _(u"OpenID %(openid_url)s is invalid" % {'openid_url':openid_url}) logging.debug(msg) return on_failure(request, msg) logging.debug('openid seemed to work') if sreg_request: logging.debug('adding sreg_request - wtf it is?') auth_request.addExtension(sreg_request) redirect_url = auth_request.redirectURL(trust_root, redirect_to) logging.debug('redirecting to %s' % redirect_url) return HttpResponseRedirect(redirect_url)
def ask_openid(request, openid_url, redirect_to, on_failure=None, sreg_request=None): """ basic function to ask openid and return response """ on_failure = on_failure or signin_failure 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") logging.debug('openid failed because i-names are not supported') return on_failure(request, msg) consumer = Consumer(request.session, util.DjangoOpenIDStore()) try: auth_request = consumer.begin(openid_url) except DiscoveryFailure: msg = _(u"OpenID %(openid_url)s is invalid" % {'openid_url': openid_url}) logging.debug(msg) return on_failure(request, msg) logging.debug('openid seemed to work') if sreg_request: logging.debug('adding sreg_request - wtf it is?') auth_request.addExtension(sreg_request) redirect_url = auth_request.redirectURL(trust_root, redirect_to) logging.debug('redirecting to %s' % redirect_url) return HttpResponseRedirect(redirect_url)
def clean_openid_url(self): """ test if openid is accepted """ if 'openid_url' in self.cleaned_data: openid_url = self.cleaned_data['openid_url'] if xri.identifierScheme(openid_url) == 'XRI' and getattr( settings, 'OPENID_DISALLOW_INAMES', False): raise forms.ValidationError(_('i-names are not supported')) return self.cleaned_data['openid_url']
def clean_openid_url(self): """ test if openid is accepted """ if 'openid_url' in self.cleaned_data: openid_url = self.cleaned_data['openid_url'] if xri.identifierScheme(openid_url) == 'XRI' and getattr( settings, 'OPENID_DISALLOW_INAMES', False ): raise forms.ValidationError(_('i-names are not supported')) return self.cleaned_data['openid_url']
def discover(identifier): if xri.identifierScheme(identifier) == "XRI": return discoverXRI(identifier) else: return discoverURI(identifier)