• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.dsa_urlopen函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中social_auth.utils.dsa_urlopen函数的典型用法代码示例。如果您正苦于以下问题:Python dsa_urlopen函数的具体用法?Python dsa_urlopen怎么用?Python dsa_urlopen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: user_data

    def user_data(self, access_token, *args, **kwargs):
        """Loads user data from service"""
        url = GITHUB_USER_DATA_URL + "?" + urlencode({"access_token": access_token})

        try:
            data = simplejson.load(dsa_urlopen(url))
        except ValueError:
            data = None

        # if we have a github organization defined, test that the current users
        # is a member of that organization.
        if data and self.GITHUB_ORGANIZATION:
            member_url = GITHUB_ORGANIZATION_MEMBER_OF_URL.format(
                org=self.GITHUB_ORGANIZATION, username=data.get("login")
            )

            try:
                response = dsa_urlopen(member_url)
            except HTTPError:
                data = None
            else:
                # if the user is a member of the organization, response code
                # will be 204, see:
                #   http://developer.github.com/v3/orgs/members/#response-if-requester-is-an-organization-member-and-user-is-a-member
                if not response.code == 204:
                    data = None

        return data
开发者ID:qrees,项目名称:django-social-auth,代码行数:28,代码来源:github.py


示例2: user_data

    def user_data(self, access_token, *args, **kwargs):
        """Loads user data from service"""
        url = GITHUB_USER_DATA_URL + '?' + urlencode({
            'access_token': access_token
        })

        try:
            data = simplejson.load(dsa_urlopen(url))
        except ValueError:
            data = None

        # if we have a github organization defined, test that the current users
        # is a member of that organization.
        if data and self.GITHUB_ORGANIZATION:
            member_url = GITHUB_ORGANIZATION_MEMBER_OF_URL.format(
                org=self.GITHUB_ORGANIZATION,
                username=data.get('login')
            ) + '?' + urlencode({
                'access_token': access_token
            })

            try:
                response = dsa_urlopen(member_url)
            except HTTPError:
                data = None
            else:
                # if the user is a member of the organization, response code
                # will be 204, see http://bit.ly/ZS6vFl
                if response.code != 204:
                    raise AuthFailed('User doesn\'t belong to the '
                                     'organization')
        return data
开发者ID:ForkRepo,项目名称:sentry,代码行数:32,代码来源:github.py


示例3: vk_api

def vk_api(method, data, is_app=False):
    """Calls VK OpenAPI method
        https://vk.com/apiclub,
        https://vk.com/pages.php?o=-1&p=%C2%FB%EF%EE%EB%ED%E5%ED%E8%E5%20%E7'
                                        %E0%EF%F0%EE%F1%EE%E2%20%EA%20API
    """

    # We need to perform server-side call if no access_token
    if not 'access_token' in data:
        if not 'v' in data:
            data['v'] = VK_API_VERSION

        if not 'api_id' in data:
            data['api_id'] = setting('VKAPP_APP_ID' if is_app else 'VK_APP_ID')

        data['method'] = method
        data['format'] = 'json'

        url = VK_SERVER_API_URL
        secret = setting('VKAPP_API_SECRET' if is_app else 'VK_API_SECRET')

        param_list = sorted(list(item + '=' + data[item] for item in data))
        data['sig'] = md5(''.join(param_list) + secret).hexdigest()
    else:
        url = VK_API_URL + method

    params = urlencode(data)
    url += '?' + params
    try:
        return json.load(dsa_urlopen(url))
    except (TypeError, KeyError, IOError, ValueError, IndexError):
        log('error', 'Could not load data from vk.com',
            exc_info=True, extra=dict(data=data))
        return None
开发者ID:ericbulloch,项目名称:django-social-auth,代码行数:34,代码来源:vk.py


示例4: auth_complete

    def auth_complete(self, *args, **kwargs):
        """Completes loging process, must return user instance"""
        access_token = None
        expires = None

        if 'code' in self.data:
            state = self.validate_state()
            url = ACCESS_TOKEN + urlencode({
                'client_id': backend_setting(self, self.SETTINGS_KEY_NAME),
                'redirect_uri': self.get_redirect_uri(state),
                'client_secret': backend_setting(
                    self,
                    self.SETTINGS_SECRET_NAME
                ),
                'code': self.data['code']
            })
            try:
                payload = dsa_urlopen(url)
            except HTTPError:
                raise AuthFailed(self, 'There was an error authenticating '
                                       'the app')

            response = payload.read()
            #parsed_response = cgi.parse_qs(response)
            parsed_response = json.loads(response)

            # print('***********************************************')
            # print(url)
            # print(response)
            # print(parsed_response)
            # print(parsed_response['access_token'])
            # print(parsed_response['expires_in'])
            # print('***********************************************')


            access_token = parsed_response['access_token']
            if 'expires' in parsed_response:
                expires = parsed_response['expires']

        if 'signed_request' in self.data:
            response = load_signed_request(
                self.data.get('signed_request'),
                backend_setting(self, self.SETTINGS_SECRET_NAME)
            )

            if response is not None:
                access_token = response.get('access_token') or\
                               response.get('oauth_token') or\
                               self.data.get('access_token')

                if 'expires' in response:
                    expires = response['expires']

        if access_token:
            return self.do_auth(access_token, expires=expires, *args, **kwargs)
        else:
            if self.data.get('error') == 'access_denied':
                raise AuthCanceled(self)
            else:
                raise AuthException(self)
开发者ID:hzlf,项目名称:openbroadcast.org,代码行数:60,代码来源:facebook.py


示例5: response

 def response(self):
     if not hasattr(self, '_response'):
         access_token = None
         expires = None
 
         if 'code' in self.data:
             state = self.validate_state()
             url = ACCESS_TOKEN + urlencode({
                 'client_id': backend_setting(self, self.SETTINGS_KEY_NAME),
                 'redirect_uri': self.get_redirect_uri(state),
                 'client_secret': backend_setting(self,
                                                  self.SETTINGS_SECRET_NAME),
                 'code': self.data['code']
             })
             try:
                 self._response = cgi.parse_qs(dsa_urlopen(url).read())
             except HTTPError:
                 raise AuthFailed(self, 'There was an error authenticating '
                                        'the app')
     
         if 'signed_request' in self.data:
             self._response = load_signed_request(self.data.get('signed_request'),
                                            backend_setting(
                                                self,
                                                self.SETTINGS_SECRET_NAME))
     return self._response
开发者ID:JordanReiter,项目名称:django-social-auth,代码行数:26,代码来源:facebook.py


示例6: user_data

    def user_data(self, access_token, *args, **kwargs):
        """
        Grab user profile information from facebook.

        returns: dict or None
        """

        data = None
        params = backend_setting(self, self.EXTRA_PARAMS_VAR_NAME, {})
        params['access_token'] = access_token
        url = FACEBOOK_ME + urlencode(params)

        try:
            response = dsa_urlopen(url)
            data = json.load(response)
        except ValueError:
            extra = {'access_token': sanitize_log_data(access_token)}
            log('error', 'Could not load user data from Facebook.',
                exc_info=True, extra=extra)
        except HTTPError:
            extra = {'access_token': sanitize_log_data(access_token)}
            log('error', 'Error validating access token.',
                exc_info=True, extra=extra)
            raise AuthTokenError(self)
        else:
            log('debug', 'Found user data for token %s',
                sanitize_log_data(access_token), extra={'data': data})
        return data
开发者ID:serkanozer,项目名称:django-social-auth,代码行数:28,代码来源:facebook.py


示例7: odnoklassniki_api

def odnoklassniki_api(data, api_url, public_key, client_secret,
                      request_type='oauth'):
    ''' Calls Odnoklassniki REST API method
        http://dev.odnoklassniki.ru/wiki/display/ok/Odnoklassniki+Rest+API
    '''
    data.update({
        'application_key': public_key,
        'format': 'JSON'
    })
    if request_type == 'oauth':
        data['sig'] = odnoklassniki_oauth_sig(data, client_secret)
    elif request_type == 'iframe_session':
        data['sig'] = odnoklassniki_iframe_sig(data,
                                               data['session_secret_key'])
    elif request_type == 'iframe_nosession':
        data['sig'] = odnoklassniki_iframe_sig(data, client_secret)
    else:
        msg = 'Unknown request type {0}. How should it be signed?'
        raise AuthFailed(msg.format(request_type))
    params = urlencode(data)
    request = Request('{0}fb.do?{1}'.format(api_url, params))
    try:
        return simplejson.loads(dsa_urlopen(request).read())
    except (TypeError, KeyError, IOError, ValueError, IndexError):
        log('error', 'Could not load data from Odnoklassniki.',
            exc_info=True, extra=dict(data=params))
        return None
开发者ID:jefftriplett,项目名称:django-social-auth,代码行数:27,代码来源:odnoklassniki.py


示例8: user_data

 def user_data(self, access_token):
     """Return user data provided"""
     # Bitbucket has a bit of an indirect route to obtain user data from an
     # authenticated query: First obtain the user's email via an
     # authenticated GET
     url = BITBUCKET_EMAIL_DATA_URL
     request = self.oauth_request(access_token, url)
     response = self.fetch_response(request)
     try:
         # Then retrieve the user's primary email address or the top email
         email_addresses = simplejson.loads(response)
         for email_address in reversed(email_addresses):
             if email_address['active']:
                 email = email_address['email']
                 if email_address['primary']:
                     break
         # Then return the user data using a normal GET with the
         # BITBUCKET_USER_DATA_URL and the user's email
         response = dsa_urlopen(BITBUCKET_USER_DATA_URL + email)
         user_details = simplejson.load(response)['user']
         user_details['email'] = email
         return user_details
     except ValueError:
         return None
     return None
开发者ID:1st,项目名称:django-social-auth,代码行数:25,代码来源:bitbucket.py


示例9: auth_complete

    def auth_complete(self, *args, **kwargs):
        """Completes loging process, must return user instance"""
        if self.data.get('error'):
            error = self.data.get('error_description') or self.data['error']
            raise AuthFailed(self, error)

        state = self.validate_state()
        client_id, client_secret = self.get_key_and_secret()
        params = {
            'grant_type': 'authorization_code',  # request auth code
            'code': self.data.get('code', ''),  # server response code
            'client_id': client_id,
            'client_secret': client_secret,
            'redirect_uri': self.get_redirect_uri(state)
        }
        headers = {'Content-Type': 'application/x-www-form-urlencoded',
                    'Accept': 'application/json'}
        request = Request(self.ACCESS_TOKEN_URL, data=urlencode(params),
                          headers=headers)

        try:
            response = simplejson.loads(dsa_urlopen(request).read())
        except HTTPError, e:
            if e.code == 400:
                raise AuthCanceled(self)
            else:
                raise
开发者ID:betonimig,项目名称:django-social-auth,代码行数:27,代码来源:__init__.py


示例10: refresh_token

 def refresh_token(cls, token):
     request = Request(
         cls.REFRESH_TOKEN_URL or cls.ACCESS_TOKEN_URL,
         data=urlencode(cls.refresh_token_params(token)),
         headers=cls.auth_headers()
     )
     return cls.process_refresh_token_response(dsa_urlopen(request).read())
开发者ID:mucca,项目名称:django-social-auth,代码行数:7,代码来源:__init__.py


示例11: user_data

 def user_data(self, access_token, *args, **kwargs):
     """Loads user data from service"""
     url = LIVE_USER_DATA_URL + "?" + urlencode({"access_token": access_token})
     try:
         return simplejson.load(dsa_urlopen(url))
     except (ValueError, IOError):
         raise AuthUnknownError("Error during profile retrieval, " "please, try again later")
开发者ID:qrees,项目名称:django-social-auth,代码行数:7,代码来源:live.py


示例12: vkontakte_api

def vkontakte_api(method, data):
    """Calls VKontakte OpenAPI method
        http://vkontakte.ru/apiclub,
        http://vkontakte.ru/pages.php?o=-1&p=%C2%FB%EF%EE%EB%ED%E5%ED%E8%E5%20
                                             %E7%E0%EF%F0%EE%F1%EE%E2%20%EA%20
                                             API
    """

    # We need to perform server-side call if no access_token
    if not "access_token" in data:
        if not "v" in data:
            data["v"] = VKONTAKTE_API_VERSION

        if not "api_id" in data:
            data["api_id"] = _api_get_val_fun("id", "VKONTAKTE_APP_ID")

        data["method"] = method
        data["format"] = "json"

        url = VKONTAKTE_SERVER_API_URL
        secret = _api_get_val_fun("key", "VKONTAKTE_APP_SECRET")

        param_list = sorted(list(item + "=" + data[item] for item in data))
        data["sig"] = md5("".join(param_list) + secret).hexdigest()
    else:
        url = VKONTAKTE_API_URL + method

    params = urlencode(data)
    url += "?" + params
    try:
        return simplejson.load(dsa_urlopen(url))
    except (TypeError, KeyError, IOError, ValueError, IndexError):
        log("error", "Could not load data from VKontakte.", exc_info=True, extra=dict(data=data))
        return None
开发者ID:jonhillmtl,项目名称:tcat,代码行数:34,代码来源:vkontakte.py


示例13: response

 def response(self):
     if not hasattr(self, '_response'):
         if self.data.get('error'):
             error = self.data.get('error_description') or self.data['error']
             raise AuthFailed(self, error)
 
         state = self.validate_state()
         client_id, client_secret = self.get_key_and_secret()
         params = {
             'grant_type': 'authorization_code',  # request auth code
             'code': self.data.get('code', ''),  # server response code
             'client_id': client_id,
             'client_secret': client_secret,
             'redirect_uri': self.get_redirect_uri(state)
         }
         headers = {'Content-Type': 'application/x-www-form-urlencoded',
                     'Accept': 'application/json'}
         request = Request(self.ACCESS_TOKEN_URL, data=urlencode(params),
                           headers=headers)
 
         try:
             self._response = simplejson.loads(dsa_urlopen(request).read())
         except HTTPError, e:
             if e.code == 400:
                 raise AuthCanceled(self)
             else:
                 raise
         except (ValueError, KeyError):
             raise AuthUnknownError(self)
开发者ID:JordanReiter,项目名称:django-social-auth,代码行数:29,代码来源:__init__.py


示例14: vkontakte_api

def vkontakte_api(method, data):
    """Calls VKontakte OpenAPI method
        http://vkontakte.ru/apiclub,
        http://vkontakte.ru/pages.php?o=-1&p=%C2%FB%EF%EE%EB%ED%E5%ED%E8%E5%20
                                             %E7%E0%EF%F0%EE%F1%EE%E2%20%EA%20
                                             API
    """

    # We need to perform server-side call if no access_token
    if not 'access_token' in data:
        if not 'v' in data:
            data['v'] = VKONTAKTE_API_VERSION

        if not 'api_id' in data:
            data['api_id'] = _api_get_val_fun('id', 'VKONTAKTE_APP_ID')

        data['method'] = method
        data['format'] = 'json'

        url = VKONTAKTE_SERVER_API_URL
        secret = _api_get_val_fun('key', 'VKONTAKTE_APP_SECRET')

        param_list = sorted(list(item + '=' + data[item] for item in data))
        data['sig'] = md5(''.join(param_list) + secret).hexdigest()
    else:
        url = VKONTAKTE_API_URL + method

    params = urlencode(data)
    url += '?' + params
    try:
        return simplejson.load(dsa_urlopen(url))
    except (TypeError, KeyError, IOError, ValueError, IndexError):
        log('error', 'Could not load data from VKontakte.',
            exc_info=True, extra=dict(data=data))
        return None
开发者ID:KrzysiekJ,项目名称:django-social-auth,代码行数:35,代码来源:vkontakte.py


示例15: user_data

 def user_data(self, access_token, *args, **kwargs):
     """Return user data provided"""
     try:
         data = dsa_urlopen(DAILYMOTION_SERVER + access_token).read()
         return simplejson.loads(data)
     except (ValueError, HTTPError):
         return None
开发者ID:IronDroid,项目名称:django-social-auth,代码行数:7,代码来源:dailymotion.py


示例16: mixcloud_profile

def mixcloud_profile(access_token):
    data = {'access_token': access_token, 'alt': 'json'}
    request = Request(MIXCLOUD_PROFILE_URL + '?' + urlencode(data))
    try:
        return simplejson.loads(dsa_urlopen(request).read())
    except (ValueError, KeyError, IOError):
        return None
开发者ID:AaronLaw,项目名称:django-social-auth,代码行数:7,代码来源:mixcloud.py


示例17: auth_complete

    def auth_complete(self, *args, **kwargs):
        """Completes loging process, must return user instance"""
        if self.data.get("error"):
            error = self.data.get("error_description") or self.data["error"]
            raise AuthFailed(self, error)

        state = self.validate_state()
        client_id, client_secret = self.get_key_and_secret()
        params = {
            "grant_type": "authorization_code",  # request auth code
            "code": self.data.get("code", ""),  # server response code
            "client_id": client_id,
            "client_secret": client_secret,
            "redirect_uri": self.get_redirect_uri(state),
        }
        headers = {"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"}
        request = Request(self.ACCESS_TOKEN_URL, data=urlencode(params), headers=headers)

        try:
            response = simplejson.loads(dsa_urlopen(request).read())
        except HTTPError, e:
            if e.code == 400:
                raise AuthCanceled(self)
            else:
                raise
开发者ID:kamotos,项目名称:django-social-auth,代码行数:25,代码来源:__init__.py


示例18: auth_complete

    def auth_complete(self, *args, **kwargs):
        """Completes loging process, must return user instance"""
        if not 'assertion' in self.data:
            raise AuthMissingParameter(self, 'assertion')

        data = urlencode({
            'assertion': self.data['assertion'],
            'audience': self.request.get_host()
        })

        try:
            response = simplejson.load(dsa_urlopen(BROWSER_ID_SERVER,
                                                   data=data))
        except ValueError:
            log('error', 'Could not load user data from BrowserID.',
                exc_info=True)
        else:
            if response.get('status') == 'failure':
                log('debug', 'Authentication failed.')
                raise AuthFailed(self)

            kwargs.update({
                'auth': self,
                'response': response,
                self.AUTH_BACKEND.name: True
            })
            return authenticate(*args, **kwargs)
开发者ID:gameolith,项目名称:django-social-auth,代码行数:27,代码来源:browserid.py


示例19: refresh_token

 def refresh_token(cls, token, redirect_uri):
     data = cls.refresh_token_params(token)
     data['redirect_uri'] = redirect_uri
     request = Request(cls.ACCESS_TOKEN_URL,
                       data=urlencode(data),
                       headers=cls.auth_headers())
     return cls.process_refresh_token_response(dsa_urlopen(request).read())
开发者ID:ericbulloch,项目名称:django-social-auth,代码行数:7,代码来源:amazon.py


示例20: user_data

 def user_data(self, access_token, *args, **kwargs):
     """Loads user data from service"""
     params = {'access_token': access_token}
     url = INSTAGRAM_CHECK_AUTH + '?' + urlencode(params)
     try:
         return simplejson.load(dsa_urlopen(url))
     except ValueError:
         return None
开发者ID:AlexanderKlyuchev,项目名称:django-social-auth,代码行数:8,代码来源:instagram.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.log函数代码示例发布时间:2022-05-27
下一篇:
Python utils.ctype_to_model函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap