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


Python _helpers._json_encode方法代碼示例

本文整理匯總了Python中oauth2client._helpers._json_encode方法的典型用法代碼示例。如果您正苦於以下問題:Python _helpers._json_encode方法的具體用法?Python _helpers._json_encode怎麽用?Python _helpers._json_encode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oauth2client._helpers的用法示例。


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

示例1: make_signed_jwt

# 需要導入模塊: from oauth2client import _helpers [as 別名]
# 或者: from oauth2client._helpers import _json_encode [as 別名]
def make_signed_jwt(signer, payload, key_id=None):
    """Make a signed JWT.

    See http://self-issued.info/docs/draft-jones-json-web-token.html.

    Args:
        signer: crypt.Signer, Cryptographic signer.
        payload: dict, Dictionary of data to convert to JSON and then sign.
        key_id: string, (Optional) Key ID header.

    Returns:
        string, The JWT for the payload.
    """
    header = {'typ': 'JWT', 'alg': 'RS256'}
    if key_id is not None:
        header['kid'] = key_id

    segments = [
        _urlsafe_b64encode(_json_encode(header)),
        _urlsafe_b64encode(_json_encode(payload)),
    ]
    signing_input = b'.'.join(segments)

    signature = signer.sign(signing_input)
    segments.append(_urlsafe_b64encode(signature))

    logger.debug(str(segments))

    return b'.'.join(segments) 
開發者ID:0x0ece,項目名稱:oscars2016,代碼行數:31,代碼來源:crypt.py

示例2: test_dictionary_input

# 需要導入模塊: from oauth2client import _helpers [as 別名]
# 或者: from oauth2client._helpers import _json_encode [as 別名]
def test_dictionary_input(self):
        # Use only a single key since dictionary hash order
        # is non-deterministic.
        data = {u'foo': 10}
        result = _helpers._json_encode(data)
        self.assertEqual(result, '{"foo":10}') 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:8,代碼來源:test__helpers.py

示例3: test_list_input

# 需要導入模塊: from oauth2client import _helpers [as 別名]
# 或者: from oauth2client._helpers import _json_encode [as 別名]
def test_list_input(self):
        data = [42, 1337]
        result = _helpers._json_encode(data)
        self.assertEqual(result, '[42,1337]') 
開發者ID:openstack,項目名稱:deb-python-oauth2client,代碼行數:6,代碼來源:test__helpers.py

示例4: _generate_assertion

# 需要導入模塊: from oauth2client import _helpers [as 別名]
# 或者: from oauth2client._helpers import _json_encode [as 別名]
def _generate_assertion(self):
        """Generate the assertion that will be used in the request."""

        header = {
            'alg': 'RS256',
            'typ': 'JWT',
            'kid': self._private_key_id
        }

        now = int(time.time())
        payload = {
            'aud': self._token_uri,
            'scope': self._scopes,
            'iat': now,
            'exp': now + _ServiceAccountCredentials.MAX_TOKEN_LIFETIME_SECS,
            'iss': self._service_account_email
        }
        payload.update(self._kwargs)

        first_segment = _urlsafe_b64encode(_json_encode(header))
        second_segment = _urlsafe_b64encode(_json_encode(payload))
        assertion_input = first_segment + b'.' + second_segment

        # Sign the assertion.
        rsa_bytes = rsa.pkcs1.sign(assertion_input, self._private_key,
                                   'SHA-256')
        signature = base64.urlsafe_b64encode(rsa_bytes).rstrip(b'=')

        return assertion_input + b'.' + signature 
開發者ID:satwikkansal,項目名稱:OneClickDTU,代碼行數:31,代碼來源:service_account.py

示例5: make_signed_jwt

# 需要導入模塊: from oauth2client import _helpers [as 別名]
# 或者: from oauth2client._helpers import _json_encode [as 別名]
def make_signed_jwt(signer, payload):
    """Make a signed JWT.

    See http://self-issued.info/docs/draft-jones-json-web-token.html.

    Args:
        signer: crypt.Signer, Cryptographic signer.
        payload: dict, Dictionary of data to convert to JSON and then sign.

    Returns:
        string, The JWT for the payload.
    """
    header = {'typ': 'JWT', 'alg': 'RS256'}

    segments = [
      _urlsafe_b64encode(_json_encode(header)),
      _urlsafe_b64encode(_json_encode(payload)),
    ]
    signing_input = b'.'.join(segments)

    signature = signer.sign(signing_input)
    segments.append(_urlsafe_b64encode(signature))

    logger.debug(str(segments))

    return b'.'.join(segments) 
開發者ID:satwikkansal,項目名稱:OneClickDTU,代碼行數:28,代碼來源:crypt.py


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