当前位置: 首页>>代码示例>>Python>>正文


Python SRegResponse.extractResponse方法代码示例

本文整理汇总了Python中openid.extensions.sreg.SRegResponse.extractResponse方法的典型用法代码示例。如果您正苦于以下问题:Python SRegResponse.extractResponse方法的具体用法?Python SRegResponse.extractResponse怎么用?Python SRegResponse.extractResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openid.extensions.sreg.SRegResponse的用法示例。


在下文中一共展示了SRegResponse.extractResponse方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_login_create_users

# 需要导入模块: from openid.extensions.sreg import SRegResponse [as 别名]
# 或者: from openid.extensions.sreg.SRegResponse import extractResponse [as 别名]
    def test_login_create_users(self):
        settings.OPENID_CREATE_USERS = True
        # Create a user with the same name as we'll pass back via sreg.
        User.objects.create_user('someuser', '[email protected]')

        # Posting in an identity URL begins the authentication request:
        response = self.client.post('/openid/login/',
            {'openid_identifier': 'http://example.com/identity',
             'next': '/getuser/'})
        self.assertContains(response, 'OpenID transaction in progress')

        # Complete the request, passing back some simple registration
        # data.  The user is redirected to the next URL.
        openid_request = self.provider.parseFormPost(response.content)
        sreg_request = SRegRequest.fromOpenIDRequest(openid_request)
        openid_response = openid_request.answer(True)
        sreg_response = SRegResponse.extractResponse(
            sreg_request, {'nickname': 'someuser', 'fullname': 'Some User',
                           'email': '[email protected]'})
        openid_response.addExtension(sreg_response)
        response = self.complete(openid_response)
        self.assertRedirects(response, 'http://testserver/getuser/')

        # And they are now logged in as a new user (they haven't taken
        # over the existing "someuser" user).
        response = self.client.get('/getuser/')
        self.assertEquals(response.content, 'someuser2')

        # Check the details of the new user.
        user = User.objects.get(username='someuser2')
        self.assertEquals(user.first_name, 'Some')
        self.assertEquals(user.last_name, 'User')
        self.assertEquals(user.email, '[email protected]')
开发者ID:gcr,项目名称:twg,代码行数:35,代码来源:test_views.py

示例2: Respond

# 需要导入模块: from openid.extensions.sreg import SRegResponse [as 别名]
# 或者: from openid.extensions.sreg.SRegResponse import extractResponse [as 别名]
  def Respond(self, oidresponse, sreg_req=False):
    """Send an OpenID response.

    Args:
      oidresponse: OpenIDResponse
      The response to send, usually created by OpenIDRequest.answer().
    """
    logging.warning('Respond: oidresponse.request.mode ' + oidresponse.request.mode)

    if oidresponse.request.mode in ['checkid_immediate', 'checkid_setup']:
      if sreg_req:
        sreg_resp = SRegResponse.extractResponse(sreg_req, {'email': self.user, 'nickname': self.user.rsplit('@',1)[0]})
        oidresponse.addExtension(sreg_resp)

    logging.debug('Using response: %s' % oidresponse)
    encoded_response = oidserver.encodeResponse(oidresponse)

    # update() would be nice, but wsgiref.headers.Headers doesn't implement it
    for header, value in encoded_response.headers.items():
      self.response.headers[header] = str(value)

    if encoded_response.code in (301, 302):
      self.redirect(self.response.headers['location'])
    else:
      self.response.set_status(encoded_response.code)

    if encoded_response.body:
      logging.debug('Sending response body: %s' % encoded_response.body)
      self.response.out.write(encoded_response.body)
    else:
      self.response.out.write('')
开发者ID:singpolyma,项目名称:Email-Verify,代码行数:33,代码来源:provider.py

示例3: createPositiveResponse

# 需要导入模块: from openid.extensions.sreg import SRegResponse [as 别名]
# 或者: from openid.extensions.sreg.SRegResponse import extractResponse [as 别名]
    def createPositiveResponse(self):
        """Create a positive assertion OpenIDResponse.

        This method should be called to create the response to
        successful checkid requests.

        If the trust root for the request is in openid_sreg_trustroots,
        then additional user information is included with the
        response.
        """
        assert self.account is not None, (
            'Must be logged in for positive OpenID response')
        assert self.openid_request is not None, (
            'No OpenID request to respond to.')

        if not self.isIdentityOwner():
            return self.createFailedResponse()

        if self.openid_request.idSelect():
            response = self.openid_request.answer(
                True, identity=self.user_identity_url)
        else:
            response = self.openid_request.answer(True)

        person = IPerson(self.account)
        sreg_fields = dict(
            nickname=person.name,
            email=person.preferredemail.email,
            fullname=self.account.displayname)
        sreg_request = SRegRequest.fromOpenIDRequest(self.openid_request)
        sreg_response = SRegResponse.extractResponse(
            sreg_request, sreg_fields)
        response.addExtension(sreg_response)

        return response
开发者ID:vitaminmoo,项目名称:unnaturalcode,代码行数:37,代码来源:server.py

示例4: Respond

# 需要导入模块: from openid.extensions.sreg import SRegResponse [as 别名]
# 或者: from openid.extensions.sreg.SRegResponse import extractResponse [as 别名]
  def Respond(self, oidresponse):
    logging.warning('Respond: oidresponse.request.mode ' + oidresponse.request.mode)

    if oidresponse.request.mode in ['checkid_immediate', 'checkid_setup']:
      user = users.get_current_user()
      if user:
        from openid.extensions.sreg import SRegRequest, SRegResponse
        sreg_req = SRegRequest.fromOpenIDRequest(oidresponse.request)
        if sreg_req.wereFieldsRequested():
          logging.info("sreg_req:%s", sreg_req.allRequestedFields())
          user_data = {'nickname':user.nickname(),
                       'email':user.email()}
          sreg_resp = SRegResponse.extractResponse(sreg_req, user_data)
          sreg_resp.toMessage(oidresponse.fields)        
    logging.info('Using response: %s' % oidresponse)
    encoded_response = oidserver.encodeResponse(oidresponse)

    for header, value in encoded_response.headers.items():
      self.response.headers[header] = str(value)

    if encoded_response.code in (301, 302):
      self.redirect(self.response.headers['location'])
    else:
      self.response.set_status(encoded_response.code)

    if encoded_response.body:
      logging.debug('Sending response body: %s' % encoded_response.body)
      self.response.out.write(encoded_response.body)
    else:
      self.response.out.write('')
开发者ID:DemocracyOS,项目名称:IdentidadEnRed-Prototype,代码行数:32,代码来源:provider.py

示例5: handle_sreg

# 需要导入模块: from openid.extensions.sreg import SRegResponse [as 别名]
# 或者: from openid.extensions.sreg.SRegResponse import extractResponse [as 别名]
def handle_sreg(request, response):
    """Handle any sreg data requests"""
    sreg_req = SRegRequest.fromOpenIDRequest(request)
    # Extract information if required
    if sreg_req.wereFieldsRequested():
        fields = config.sreg_fields()
        if not fields:
            return
        sreg_resp = SRegResponse.extractResponse(sreg_req, config.sreg_fields())
        sreg_resp.toMessage(response.fields)
开发者ID:kgaughan,项目名称:poit-wsgi,代码行数:12,代码来源:poit.py

示例6: Respond

# 需要导入模块: from openid.extensions.sreg import SRegResponse [as 别名]
# 或者: from openid.extensions.sreg.SRegResponse import extractResponse [as 别名]
  def Respond(self, oidresponse):
    """Send an OpenID response.

    Args:
      oidresponse: OpenIDResponse
      The response to send, usually created by OpenIDRequest.answer().
    """
    logging.warning('Respond: oidresponse.request.mode ' + oidresponse.request.mode)

    if oidresponse.request.mode in ['checkid_immediate', 'checkid_setup']:
      # user = users.get_current_user()
      user = self.get_current_user()
      if user:
        from openid.extensions.sreg import SRegRequest,SRegResponse
        sreg_req = SRegRequest.fromOpenIDRequest(oidresponse.request)
        logging.info("sreg_req:%s",sreg_req.allRequestedFields())
        if sreg_req.wereFieldsRequested():
          user_data = {'nickname':user.nickname,
                       'email':user.email}
          sreg_resp = SRegResponse.extractResponse(sreg_req, user_data)
          sreg_resp.toMessage(oidresponse.fields)
        # add nickname, using the Simple Registration Extension:
        # http://www.openidenabled.com/openid/simple-registration-extension/
        #oidresponse.fields.setArg('http://openid.net/sreg/1.0', 'nickname', user.nickname)
        #oidresponse.fields.setArg('http://openid.net/sreg/1.0', 'email', user.email)
        #oidresponse.fields.setArg('http://openid.net/srv/ax/1.0', 'nickname', user.nickname)
        #oidresponse.fields.setArg('http://openid.net/srv/ax/1.0', 'email', user.email)
        from openid.extensions.ax import FetchRequest, FetchResponse	
        res ={'nickname':user.nickname,'email':user.email,'attr0':user.email,'attr1':user.nickname}
        ax_req = FetchRequest.fromOpenIDRequest(oidresponse.request)
        logging.info("ax_req:%s",ax_req.getRequiredAttrs())
        ax_res = FetchResponse()
        for x in ax_req.iterAttrs():
          ax_res.addValue(x.type_uri,res[x.alias] )
        ax_res.toMessage(oidresponse.fields)       
        pass
    logging.info('Using response: %s' % oidresponse)
    encoded_response = oidserver.encodeResponse(oidresponse)

    # update() would be nice, but wsgiref.headers.Headers doesn't implement it
    for header, value in encoded_response.headers.items():
      self.response.headers[header] = str(value)

    if encoded_response.code in (301, 302):
      self.redirect(self.response.headers['location'])
    else:
      self.response.set_status(encoded_response.code)

    if encoded_response.body:
      logging.debug('Sending response body: %s' % encoded_response.body)
      self.response.out.write(encoded_response.body)
    else:
      self.response.out.write('')
开发者ID:patou,项目名称:facebook-openid,代码行数:55,代码来源:provider.py

示例7: add_sreg_fields

# 需要导入模块: from openid.extensions.sreg import SRegResponse [as 别名]
# 或者: from openid.extensions.sreg.SRegResponse import extractResponse [as 别名]
 def add_sreg_fields(self, oidresponse, user):
     """
     Add requested Simple Registration Extension fields to oidresponse
     and return it.
     """
     sreg_req = SRegRequest.fromOpenIDRequest(oidresponse.request)
     if sreg_req.wereFieldsRequested():
         logging.debug("respond: sreg_req:%s",
                       sreg_req.allRequestedFields())
         sreg_map = dict(
             ((key, val) for (key, val) in 
              {'nickname':user.nickname(), 'email':user.email()}.items()
              if key in sreg_req.allRequestedFields()))
         oidresponse.addExtension(
             SRegResponse.extractResponse(sreg_req, sreg_map))
     return oidresponse
开发者ID:jpellerin,项目名称:duo_web,代码行数:18,代码来源:provider.py

示例8: _add_user_attribs

# 需要导入模块: from openid.extensions.sreg import SRegResponse [as 别名]
# 或者: from openid.extensions.sreg.SRegResponse import extractResponse [as 别名]
def _add_user_attribs(request, openid_request, openid_response):
    # Add ax and sreg result data
    sreg_request = SRegRequest.fromOpenIDRequest(openid_request)
    ax_request = ax.FetchRequest.fromOpenIDRequest(openid_request)
    rpconfig = utils.get_rpconfig(openid_request.trust_root)
    form = UserAttribsRequestForm(
        request, sreg_request, ax_request, rpconfig)
    if form.data_approved_for_request:
        sreg_response = SRegResponse.extractResponse(
            sreg_request, form.data_approved_for_request)
        openid_response.addExtension(sreg_response)
        if ax_request is not None:
            ax_response = ax.FetchResponse(ax_request)
            for k, v in form.data_approved_for_request.iteritems():
                if AX_DATA_FIELDS.getNamespaceURI(k) in ax_request:
                    ax_response.addValue(AX_DATA_FIELDS.getNamespaceURI(k), v)
            openid_response.addExtension(ax_response)
开发者ID:miing,项目名称:mci_migo,代码行数:19,代码来源:server.py

示例9: Respond

# 需要导入模块: from openid.extensions.sreg import SRegResponse [as 别名]
# 或者: from openid.extensions.sreg.SRegResponse import extractResponse [as 别名]
  def Respond(self, oidresponse):
    """Send an OpenID response.

    Args:
      oidresponse: OpenIDResponse
      The response to send, usually created by OpenIDRequest.answer().
    """
    logging.info('Respond: oidresponse.request.mode ' + oidresponse.request.mode)

    if oidresponse.request.mode in ['checkid_immediate', 'checkid_setup']:
      user = Auth.AuthenticatedUser(self.request)
      if user:
        from openid.extensions.sreg import SRegRequest,SRegResponse
        sreg_req = SRegRequest.fromOpenIDRequest(oidresponse.request)
        if sreg_req.wereFieldsRequested():
          logging.info("sreg_req:%s",sreg_req.allRequestedFields())
          user_data = {'nickname':user.nickname(),
                       'email':user.email}
          sreg_resp = SRegResponse.extractResponse(sreg_req, user_data)
          sreg_resp.toMessage(oidresponse.fields)        
        # add nickname, using the Simple Registration Extension:
        # http://www.openidenabled.com/openid/simple-registration-extension/
#mrk
#        oidresponse.fields.setArg('http://openid.net/sreg/1.0', 'nickname', user.nickname())
#        oidresponse.fields.setArg('http://openid.net/sreg/1.0', 'email', user.email())
        pass
    logging.info('Using response: %s' % oidresponse)
    encoded_response = oidserver.encodeResponse(oidresponse)

    # update() would be nice, but wsgiref.headers.Headers doesn't implement it
    for header, value in encoded_response.headers.items():
      self.response.headers[header] = str(value)

    if encoded_response.code in (301, 302):
      self.redirect(self.response.headers['location'])
    else:
      self.response.set_status(encoded_response.code)

    if encoded_response.body:
      logging.debug('Sending response body: %s' % encoded_response.body)
      self.response.out.write(encoded_response.body)
    else:
      self.response.out.write('')
开发者ID:wibge,项目名称:EncSubServer,代码行数:45,代码来源:OpenIdProvider.py

示例10: test_login_update_details

# 需要导入模块: from openid.extensions.sreg import SRegResponse [as 别名]
# 或者: from openid.extensions.sreg.SRegResponse import extractResponse [as 别名]
    def test_login_update_details(self):
        settings.OPENID_UPDATE_DETAILS_FROM_SREG = True
        user = User.objects.create_user('testuser', '[email protected]')
        useropenid = UserOpenID(
            user=user,
            claimed_id='http://example.com/identity',
            display_id='http://example.com/identity')
        useropenid.save()

        # Posting in an identity URL begins the authentication request:
        response = self.client.post('/openid/login/',
            {'openid_identifier': 'http://example.com/identity',
             'next': '/getuser/'})
        self.assertContains(response, 'OpenID transaction in progress')

        # Complete the request, passing back some simple registration
        # data.  The user is redirected to the next URL.
        openid_request = self.provider.parseFormPost(response.content)
        sreg_request = SRegRequest.fromOpenIDRequest(openid_request)
        openid_response = openid_request.answer(True)
        sreg_response = SRegResponse.extractResponse(
            sreg_request, {'nickname': 'someuser', 'fullname': 'Some User',
                           'email': '[email protected]'})
        openid_response.addExtension(sreg_response)
        response = self.complete(openid_response)
        self.assertRedirects(response, 'http://testserver/getuser/')

        # And they are now logged in as testuser (the passed in
        # nickname has not caused the username to change).
        response = self.client.get('/getuser/')
        self.assertEquals(response.content, 'testuser')

        # The user's full name and email have been updated.
        user = User.objects.get(username='testuser')
        self.assertEquals(user.first_name, 'Some')
        self.assertEquals(user.last_name, 'User')
        self.assertEquals(user.email, '[email protected]')
开发者ID:gcr,项目名称:twg,代码行数:39,代码来源:test_views.py

示例11: reverse

# 需要导入模块: from openid.extensions.sreg import SRegResponse [as 别名]
# 或者: from openid.extensions.sreg.SRegResponse import extractResponse [as 别名]
        # Create a directed identity if needed
        if identity == IDENTIFIER_SELECT:
            hash = hashlib.sha1(str(request.user.id)+'|'+orequest.trust_root) \
                    .hexdigest()
            claimed_id = request.build_absolute_uri(
                    reverse('openid-provider-identity', args=[hash]))
            logger.info('Giving directed identity %r to trusted root %r \
with sreg data %s' % (claimed_id, orequest.trust_root, user_data))
        else:
            claimed_id = identity
            logger.info('Giving claimed identity %r to trusted root %r \
with sreg data %s' % (claimed_id, orequest.trust_root, user_data))

        oresponse = orequest.answer(True, identity=claimed_id)
        sreg_response = SRegResponse.extractResponse(sreg_request, user_data)
        oresponse.addExtension(sreg_response)
    else:
        oresponse = server.handleRequest(orequest)
    logger.info('Returning OpenID response %s' % oresponse)
    return oresponse_to_response(server, oresponse)

def openid_xrds(request, identity=False, id=None):
    '''XRDS discovery page'''
    logger.debug('OpenID XRDS identity:%(identity)s id:%(id)s' % locals())
    if identity:
        types = [OPENID_2_0_TYPE, OPENID_1_0_TYPE, OPENID_1_1_TYPE, SREG_TYPE]
        local_ids = []
    else:
        types = [OPENID_IDP_2_0_TYPE,SREG_TYPE]
        local_ids = []
开发者ID:pu239ppy,项目名称:authentic2,代码行数:32,代码来源:views.py

示例12: openid_auth_site

# 需要导入模块: from openid.extensions.sreg import SRegResponse [as 别名]
# 或者: from openid.extensions.sreg.SRegResponse import extractResponse [as 别名]
def openid_auth_site(request):
    try:
        oreq = request.session['openid_request']
    except KeyError:
        return render(request, 'openid-auth-site.html', {
            'error': 'No OpenID request associated. The request may have \
            expired.',
        }, status=400)

    sreg = SRegRequest.fromOpenIDRequest(oreq)
    ax = FetchRequest.fromOpenIDRequest(oreq)

    sreg_fields = set(sreg.allRequestedFields())
    if ax:
        for uri in ax.requested_attributes:
            k = openid_ax_attribute_mapping.get(uri)
            if k:
                sreg_fields.add(k)

    ldap_user = LDAPUser.objects.get(username=request.user.username)
    if sreg_fields:
        sreg_data = {
            'nickname': ldap_user.username,
            'email': ldap_user.email,
            'fullname': ldap_user.full_name,
            'dob': ldap_user.birthday,
        }

        for k in list(sreg_data):
            if not sreg_data[k]:
                del sreg_data[k]
    else:
        sreg_data = {}
    sreg_fields = sreg_data.keys()

    # Read preferences from the db.
    try:
        saved_pref = OpenID_Attributes.objects.get(
            uid=ldap_user.uid,
            trust_root=oreq.trust_root,
        )
    except OpenID_Attributes.DoesNotExist:
        saved_pref = None
        auto_auth = False
    else:
        auto_auth = saved_pref.always_auth

    if auto_auth or request.POST:
        if auto_auth:
            # TODO: can we do this nicer?
            form_inp = model_to_dict(saved_pref)
        else:
            form_inp = request.POST
        form = SiteAuthForm(form_inp, instance=saved_pref)
        # can it be invalid somehow?
        assert(form.is_valid())
        attrs = form.save(commit=False)

        # nullify fields that were not requested
        for fn in form.cleaned_data:
            if fn in ('always_auth',):
                pass
            elif hasattr(attrs, fn) and fn not in sreg_fields:
                setattr(attrs, fn, None)

        if auto_auth or 'accept' in request.POST:
            # prepare sreg response
            for fn, send in form.cleaned_data.items():
                if fn not in sreg_data:
                    pass
                elif not send:
                    del sreg_data[fn]
                elif isinstance(sreg_data[fn], list):
                    form_key = 'which_%s' % fn
                    val = form.cleaned_data[form_key]
                    if val not in sreg_data[fn]:
                        raise NotImplementedError(
                            'Changing choices not implemented yet')
                    sreg_data[fn] = val
                    if not auto_auth:
                        setattr(attrs, form_key, val)

            if not auto_auth:
                # save prefs in the db
                # (if auto_auth, then nothing changed)
                attrs.uid = ldap_user.uid
                attrs.trust_root = oreq.trust_root
                attrs.save()

            oresp = oreq.answer(True, identity=request.build_absolute_uri(
                reverse(user_page, args=(request.user.username,))))

            sreg_resp = SRegResponse.extractResponse(sreg, sreg_data)
            oresp.addExtension(sreg_resp)

            if ax:
                ax_resp = FetchResponse(ax)
                for uri in ax.requested_attributes:
                    k = openid_ax_attribute_mapping.get(uri)
                    if k and k in sreg_data:
#.........这里部分代码省略.........
开发者ID:mgorny,项目名称:identity.gentoo.org,代码行数:103,代码来源:views.py


注:本文中的openid.extensions.sreg.SRegResponse.extractResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。