當前位置: 首頁>>代碼示例>>Python>>正文


Python ax.FetchRequest類代碼示例

本文整理匯總了Python中openid.extensions.ax.FetchRequest的典型用法代碼示例。如果您正苦於以下問題:Python FetchRequest類的具體用法?Python FetchRequest怎麽用?Python FetchRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了FetchRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: begin

def begin(request, openid_url):
    request.session['request_referer'] = urlparse.urljoin(request.META.get('HTTP_REFERER', ''), '/')
    
    consumer = Consumer(request.session, DjangoOpenIDStore())
 
    try:
        auth_request = consumer.begin(openid_url)
    except DiscoveryFailure:
        return on_failure(request, _('The OpenID was invalid'))
    
    s = SRegRequest()        
    for sarg in OPENID_SREG:
        if sarg.lower().lstrip() == "policy_url":
            s.policy_url = OPENID_SREG[sarg]
        else:
            for v in OPENID_SREG[sarg].split(','):
                s.requestField(field_name=v.lower().lstrip(), required=(sarg.lower().lstrip() == "required"))
    auth_request.addExtension(s)  
    
    axr = AXFetchRequest()
    for i in OPENID_AX:
        axr.add(AttrInfo(i['type_uri'], i['count'], i['required'], i['alias']))
    auth_request.addExtension(axr)
 
    redirect_url = auth_request.redirectURL(get_trusted_root(request),
                                            request.build_absolute_uri(reverse("openid_complete")))
    
    return HttpResponseRedirect(redirect_url)
開發者ID:Zojax,項目名稱:zojax.django.socialauthentication,代碼行數:28,代碼來源:views.py

示例2: begin

    def begin(self, request, data):
        try:
            openid_url = data['openid_url'].strip()
        except KeyError:
            messages.error(request, lang.FILL_OPENID_URL)
            return redirect('netauth-login')

        # allow user to type openid provider without http:// prefix
        if not openid_url.startswith("http"):
            openid_url = "http://%s" % openid_url

        return_url = request.build_absolute_uri(reverse('netauth-complete', args=[self.provider]))
        request.session['openid_return_to'] = return_url
        client = consumer.Consumer(request.session, None)

        try:
            openid_request = client.begin(openid_url)
            sreg_extra = [value for __, value in self.PROFILE_MAPPING.items()]
            sreg = SRegRequest(required=sreg_extra)
            openid_request.addExtension(sreg)
            ax_msg = FetchRequest()
            for __, detail in self.PROFILE_MAPPING.items():
                ax_msg.add(AttrInfo(settings.AX_URIS[detail], required=True))
            openid_request.addExtension(ax_msg)

            redirect_url = openid_request.redirectURL(realm='http://' + request.get_host(), return_to=return_url)
            return redirect(redirect_url)

        except discover.DiscoveryFailure:
            messages.error(request, _('Could not find OpenID server'))
            return redirect('netauth-login')
開發者ID:ilblackdragon,項目名稱:django-netauth,代碼行數:31,代碼來源:openid.py

示例3: login

def login(request):
    if 'openid' in request.GET or request.method == 'POST':
        form = LoginForm(request.REQUEST)
        if form.is_valid():
            client = _openid_consumer(request)
            try:
                auth_request = client.begin(form.cleaned_data['openid'])
                if QUERY_EMAIL:
                    sreg = SRegRequest()
                    sreg.requestField(field_name=SRegField.EMAIL, required=True)
                    auth_request.addExtension(sreg)
                    ax = FetchRequest()
                    ax.add(AttrInfo(AXAttribute.CONTACT_EMAIL,
                                    required=True))
                    auth_request.addExtension(ax)
                callback_url = reverse(callback)
                state = SocialLogin.marshall_state(request)
                callback_url = callback_url + '?' + urlencode(dict(state=state))
                redirect_url = auth_request.redirectURL(
                    request.build_absolute_uri('/'),
                    request.build_absolute_uri(callback_url))
                return HttpResponseRedirect(redirect_url)
            except DiscoveryFailure, e:
                if request.method == 'POST':
                    form._errors["openid"] = form.error_class([e])
                else:
                    return render_authentication_error(request)
開發者ID:CARocha,項目名稱:django-allauth,代碼行數:27,代碼來源:views.py

示例4: login

def login(request):
    if 'openid' in request.GET or request.method == 'POST':
        form = LoginForm(request.REQUEST)
        if form.is_valid():
            client = _openid_consumer(request)
            try:
                auth_request = client.begin(form.cleaned_data['openid'])
                if QUERY_EMAIL:
                    sreg = SRegRequest()
                    sreg.requestField(field_name=SRegField.EMAIL,
                                      required=True)
                    auth_request.addExtension(sreg)
                    ax = FetchRequest()
                    ax.add(AttrInfo(AXAttribute.CONTACT_EMAIL,
                                    required=True))
                    auth_request.addExtension(ax)
                callback_url = reverse(callback)
                SocialLogin.stash_state(request)
                redirect_url = auth_request.redirectURL(
                    request.build_absolute_uri('/'),
                    request.build_absolute_uri(callback_url))
                return HttpResponseRedirect(redirect_url)
            # UnicodeDecodeError:
            # see https://github.com/necaris/python3-openid/issues/1
            except (UnicodeDecodeError, DiscoveryFailure) as e:
                if request.method == 'POST':
                    form._errors["openid"] = form.error_class([e])
                else:
                    return render_authentication_error(request)
    else:
        form = LoginForm()
    d = dict(form=form)
    return render_to_response('openid/login.html',
                              d, context_instance=RequestContext(request))
開發者ID:aehlke,項目名稱:django-allauth,代碼行數:34,代碼來源:views.py

示例5: test02

 def test02(self):
     interface = SQLAlchemyAXInterface()
     interface.connectionString = \
         SQLAlchemyAXInterfaceTestCase.DB_CONNECTION_STR
         
     interface.attributeNames = ('firstName', 'lastName', 'emailAddress')
     
     interface.sqlQuery = ("select firstname, lastname, emailAddress from "
                           "users where username = '${username}'")
     
     axReq = FetchRequest()
     
     for typeURI in interface.attributeNames:
         axReq.add(AttrInfo(typeURI, required=True))
         
     axResp = FetchResponse()
     
     authnCtx = {
         SQLAlchemyAXInterface.USERNAME_SESSION_KEYNAME: 
             SQLAlchemyAXInterfaceTestCase.USERNAME
     }
     
     interface(axReq, axResp, None, authnCtx)
     axData = axResp.getExtensionArgs()
     self.assert_(len(axData.keys()) > 0)
     print(axData)
                           
開發者ID:cedadev,項目名稱:ndg_security_server,代碼行數:26,代碼來源:test_axinterface.py

示例6: login

def login(request):
    if 'openid' in request.GET or request.method == 'POST':
        form = LoginForm(
            dict(list(request.GET.items()) + list(request.POST.items()))
        )
        if form.is_valid():
            client = _openid_consumer(request)
            provider = OpenIDProvider(request)
            realm = provider.get_settings().get(
                'REALM',
                request.build_absolute_uri('/'))
            try:
                auth_request = client.begin(form.cleaned_data['openid'])
                if QUERY_EMAIL:
                    sreg = SRegRequest()
                    for name in SRegFields:
                        sreg.requestField(field_name=name,
                                          required=True)
                    auth_request.addExtension(sreg)
                    ax = FetchRequest()
                    for name in AXAttributes:
                        ax.add(AttrInfo(name,
                                        required=True))
                    provider = OpenIDProvider(request)
                    server_settings = \
                        provider.get_server_settings(request.GET.get('openid'))
                    extra_attributes = \
                        server_settings.get('extra_attributes', [])
                    for _, name, required in extra_attributes:
                        ax.add(AttrInfo(name,
                                        required=required))
                    auth_request.addExtension(ax)
                callback_url = reverse(callback)
                SocialLogin.stash_state(request)
                # Fix for issues 1523 and 2072 (github django-allauth)
                if 'next' in form.cleaned_data and form.cleaned_data['next']:
                    auth_request.return_to_args['next'] = \
                        form.cleaned_data['next']
                redirect_url = auth_request.redirectURL(
                    realm,
                    request.build_absolute_uri(callback_url))
                return HttpResponseRedirect(redirect_url)
            # UnicodeDecodeError:
            # see https://github.com/necaris/python3-openid/issues/1
            except (UnicodeDecodeError, DiscoveryFailure) as e:
                if request.method == 'POST':
                    form._errors["openid"] = form.error_class([e])
                else:
                    return render_authentication_error(
                        request,
                        OpenIDProvider.id,
                        exception=e)
    else:
        form = LoginForm(initial={'next': request.GET.get('next'),
                                  'process': request.GET.get('process')})
    d = dict(form=form)
    return render(request, "openid/login.html", d)
開發者ID:biwin,項目名稱:django-allauth,代碼行數:57,代碼來源:views.py

示例7: test_ax_and_sreg_required_fields_for_trusted_site

 def test_ax_and_sreg_required_fields_for_trusted_site(self):
     """The server should always return values for required fields to
     trusted sites, regardless of the state of the checkbox in the UI.
     Optional fields should not be returned if the user has unchecked them.
     Fields are required if at least one of the SReg and AX request lists
     them as such.
     """
     self.rpconfig.allowed_user_attribs = (
         'fullname,email,language,account_verified')
     sreg_request = SRegRequest(
         required=['language', 'email'], optional=['fullname'])
     ax_request = FetchRequest()
     ax_request.add(
         AttrInfo(AX_URI_EMAIL, alias='email', required=True))
     ax_request.add(
         AttrInfo(AX_URI_ACCOUNT_VERIFIED, alias='account_verified',
                  required=True))
     ax_request.add(
         AttrInfo(AX_URI_LANGUAGE, alias='language', required=False))
     ax_request.add(
         AttrInfo(AX_URI_FULL_NAME, alias='fullname', required=False))
     form = UserAttribsRequestForm(
         request=self._get_request_with_post_args(),
         sreg_request=sreg_request, ax_request=ax_request,
         rpconfig=self.rpconfig)
     self.assertIn('email', form.data_approved_for_request)
     self.assertIn('account_verified', form.data_approved_for_request)
     self.assertIn('language', form.data_approved_for_request)
     self.assertNotIn('fullname', form.data_approved_for_request)
開發者ID:miing,項目名稱:mci_migo,代碼行數:29,代碼來源:test_forms.py

示例8: prepare_authentication_request

    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

        user_url = self.get_user_url(request)

        if xri.identifierScheme(user_url) == 'XRI' and getattr(
            settings, 'OPENID_DISALLOW_INAMES', False
        ):
            raise InvalidAuthentication('i-names are not supported')

        consumer = Consumer(request.session, OsqaOpenIDStore())

        try:
            auth_request = consumer.begin(user_url)
        except DiscoveryFailure:
            raise InvalidAuthentication(_('Sorry, but your input is not a valid OpenId'))

        sreg = getattr(self, 'sreg_attributes', False)

        if sreg:
            s = SRegRequest()

            for k, attr_dic in sreg.items():
                if k == "policy_url":
                    s.policy_url = attr_dic
                    continue

                for attr_name in attr_dic.keys():
                    s.requestField(field_name=attr_name, required=(k == "required"))

            auth_request.addExtension(s)

        ax_schema = getattr(self, 'dataype2ax_schema', False)

        if ax_schema and request.session.get('force_email_request', True):
            axr = AXFetchRequest()
            for data_type, schema in ax_schema.items():
                if isinstance(schema, tuple):
                    axr.add(AttrInfo(schema[0], 1, True, schema[1]))
                else:
                    axr.add(AttrInfo(schema, 1, True, data_type))

            auth_request.addExtension(axr)

        trust_root = getattr(
            settings, 'OPENID_TRUST_ROOT', get_url_host(request) + '/'
        )

        return auth_request.redirectURL(trust_root, redirect_to)
開發者ID:Granicus,項目名稱:civipedia,代碼行數:50,代碼來源:consumer.py

示例9: test_ax_optional_fields_for_untrusted_site

 def test_ax_optional_fields_for_untrusted_site(self):
     """The server should return values for optional fields to untrusted
     sites only when the user checks the checkbox in the UI.
     """
     post_args = {'fullname': 'fullname'}
     ax_request = FetchRequest()
     for (attr, alias) in [
             (AX_URI_FULL_NAME, 'fullname'),
             (AX_URI_EMAIL, 'email')]:
         ax_request.add(AttrInfo(attr, alias=alias, required=False))
     form = UserAttribsRequestForm(
         request=self._get_request_with_post_args(post_args),
         sreg_request=None, ax_request=ax_request, rpconfig=None)
     self.assertTrue('fullname' in form.data_approved_for_request)
     self.assertFalse('email' in form.data_approved_for_request)
開發者ID:miing,項目名稱:mci_migo,代碼行數:15,代碼來源:test_forms.py

示例10: test_ax_required_fields_for_trusted_site

 def test_ax_required_fields_for_trusted_site(self):
     """The server should always return values for required fields to
     trusted sites, regardless of the state of the checkbox in the UI.
     Optional fields should not be returned if the user has unchecked them.
     """
     self.rpconfig.allowed_user_attribs = 'fullname,email'
     ax_request = FetchRequest()
     ax_request.add(
         AttrInfo(AX_URI_FULL_NAME, alias='fullname', required=True))
     ax_request.add(
         AttrInfo(AX_URI_EMAIL, alias='email', required=False))
     form = UserAttribsRequestForm(
         request=self._get_request_with_post_args(), sreg_request=None,
         ax_request=ax_request, rpconfig=self.rpconfig)
     self.assertIn('fullname', form.data_approved_for_request)
     self.assertNotIn('email', form.data_approved_for_request)
開發者ID:miing,項目名稱:mci_migo,代碼行數:16,代碼來源:test_forms.py

示例11: prepare_authentication_request

    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

        user_url = self.get_user_url(request)

        if xri.identifierScheme(user_url) == 'XRI' and getattr(
            settings, 'OPENID_DISALLOW_INAMES', False
        ):
            raise InvalidAuthentication('i-names are not supported')

        consumer = Consumer(request.session, OsqaOpenIDStore())

        try:
            auth_request = consumer.begin(user_url)
        except DiscoveryFailure:
            raise InvalidAuthentication(_('Sorry, but your input is not a valid OpenId'))

        #sreg = getattr(settings, 'OPENID_SREG', False)

        #if sreg:
        #    s = SRegRequest()
        #    for sarg in sreg:
        #        if sarg.lower().lstrip() == "policy_url":
        #            s.policy_url = sreg[sarg]
        #        else:
        #            for v in sreg[sarg].split(','):
        #                s.requestField(field_name=v.lower().lstrip(), required=(sarg.lower().lstrip() == "required"))
        #    auth_request.addExtension(s)

        #auth_request.addExtension(SRegRequest(required=['email']))

        if request.session.get('force_email_request', True):
            axr = AXFetchRequest()
            for data_type, schema in self.dataype2ax_schema.items():
                if isinstance(schema, tuple):
                    axr.add(AttrInfo(schema[0], 1, True, schema[1]))
                else:
                    axr.add(AttrInfo(schema, 1, True, data_type))

            auth_request.addExtension(axr)

        trust_root = getattr(
            settings, 'OPENID_TRUST_ROOT', get_url_host(request) + '/'
        )

        return auth_request.redirectURL(trust_root, redirect_to)
開發者ID:boothead,項目名稱:OSQA,代碼行數:47,代碼來源:consumer.py

示例12: test_no_approved_fields_without_post_request

 def test_no_approved_fields_without_post_request(self):
     """The server should not generate a list of approved fields when the
     request is not a POST request.
     """
     sreg_request = SRegRequest(required=['fullname', 'email'])
     ax_request = FetchRequest()
     for (attr, alias) in [
             (AX_URI_FULL_NAME, 'fullname'),
             (AX_URI_EMAIL, 'email')]:
         ax_request.add(AttrInfo(attr, alias=alias, required=True))
     request = self._get_request_with_post_args()
     request.META['REQUEST_METHOD'] = 'GET'
     form = UserAttribsRequestForm(request=request,
                                   sreg_request=sreg_request,
                                   ax_request=ax_request,
                                   rpconfig=self.rpconfig)
     self.assertEqual(len(form.data_approved_for_request), 0)
開發者ID:miing,項目名稱:mci_migo,代碼行數:17,代碼來源:test_forms.py

示例13: test_ax_checkbox_status_for_trusted_site

 def test_ax_checkbox_status_for_trusted_site(self):
     """Checkboxes are always checked if the site is trusted"""
     self.rpconfig.allowed_user_attribs = 'fullname,email'
     ax_request = FetchRequest()
     ax_request.add(
         AttrInfo(AX_URI_FULL_NAME, alias='fullname', required=True))
     ax_request.add(
         AttrInfo(AX_URI_EMAIL, alias='email', required=False))
     form = UserAttribsRequestForm(
         request=self._get_request_with_post_args(),
         sreg_request=None, ax_request=ax_request, rpconfig=self.rpconfig)
     # True because fullname required
     self.assertTrue(form.check_test('fullname')(True))
     # True because trusted site and no previous disapproval
     self.assertTrue(form.check_test('email')(True))
     # Throw in an unrequested field for good measure
     self.assertFalse(form.check_test('language')(True))
開發者ID:miing,項目名稱:mci_migo,代碼行數:17,代碼來源:test_forms.py

示例14: test_ax_fields_for_trusted_auto_authorize_site

 def test_ax_fields_for_trusted_auto_authorize_site(self):
     """The server should always return values for requested fields to
     trusted sites configured to auto-authorize.
     """
     self.rpconfig.allowed_user_attribs = 'fullname,email'
     self.rpconfig.auto_authorize = True
     ax_request = FetchRequest()
     # One required attribute
     ax_request.add(
         AttrInfo(AX_URI_FULL_NAME, alias='fullname', required=True))
     # One optional attribute
     ax_request.add(
         AttrInfo(AX_URI_EMAIL, alias='email', required=False))
     form = UserAttribsRequestForm(
         request=self._get_request_with_post_args(), sreg_request=None,
         ax_request=ax_request, rpconfig=self.rpconfig)
     # Both attributes should be returned
     self.assertIn('fullname', form.data_approved_for_request)
     self.assertIn('email', form.data_approved_for_request)
開發者ID:miing,項目名稱:mci_migo,代碼行數:19,代碼來源:test_forms.py

示例15: perform_openid_auth

    def perform_openid_auth(self, form):
        if not form.is_valid():
            return form

        request = self.request
        client = self.get_client()
        provider = self.provider(request)
        realm = self.get_realm(provider)

        auth_request = client.begin(form.cleaned_data['openid'])
        if QUERY_EMAIL:
            sreg = SRegRequest()
            for name in SRegFields:
                sreg.requestField(
                    field_name=name, required=True
                )
            auth_request.addExtension(sreg)
            ax = FetchRequest()
            for name in AXAttributes:
                ax.add(AttrInfo(name,
                                required=True))
            provider = OpenIDProvider(request)
            server_settings = \
                provider.get_server_settings(request.GET.get('openid'))
            extra_attributes = \
                server_settings.get('extra_attributes', [])
            for _, name, required in extra_attributes:
                ax.add(AttrInfo(name,
                                required=required))
            auth_request.addExtension(ax)

        SocialLogin.stash_state(request)

        # Fix for issues 1523 and 2072 (github django-allauth)
        if "next" in form.cleaned_data and form.cleaned_data["next"]:
            auth_request.return_to_args['next'] = \
                form.cleaned_data['next']
        redirect_url = auth_request.redirectURL(
            realm,
            request.build_absolute_uri(self.get_callback_url()))
        return HttpResponseRedirect(redirect_url)
開發者ID:jleclanche,項目名稱:django-allauth,代碼行數:41,代碼來源:views.py


注:本文中的openid.extensions.ax.FetchRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。