auth.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:gdata-python3 作者: dvska 项目源码 文件源码
def GetAuthHeader(self, http_method, http_url):
        """Generates the Authorization header.

        The form of the secure AuthSub Authorization header is
        Authorization: AuthSub token="token" sigalg="sigalg" data="data" sig="sig"
        and  data represents a string in the form
        data = http_method http_url timestamp nonce

        Args:
          http_method: string HTTP method i.e. operation e.g. GET, POST, PUT, etc.
          http_url: string or atom.url.Url HTTP URL to which request is made.

        Returns:
          dict Header to be sent with every subsequent request after authentication.
        """
        timestamp = int(math.floor(time.time()))
        nonce = '%lu' % random.randrange(1, 2 ** 64)
        data = '%s %s %d %s' % (http_method, str(http_url), timestamp, nonce)
        # noinspection PyDeprecation
        sig = encodebytes(str(self.rsa_key.hashAndSign(data))).rstrip()
        header = {'Authorization': '%s"%s" data="%s" sig="%s" sigalg="rsa-sha1"' %
                                   (AUTHSUB_AUTH_LABEL, self.token_string, data, sig)}
        return header
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号