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


Python crypt.make_signed_jwt方法代碼示例

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


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

示例1: _generate_assertion

# 需要導入模塊: from oauth2client import crypt [as 別名]
# 或者: from oauth2client.crypt import make_signed_jwt [as 別名]
def _generate_assertion(self):
    """Generate the assertion that will be used in the request."""
    now = long(time.time())
    payload = {
        'aud': self.token_uri,
        'scope': self.scope,
        'iat': now,
        'exp': now + SignedJwtAssertionCredentials.MAX_TOKEN_LIFETIME_SECS,
        'iss': self.service_account_name
    }
    payload.update(self.kwargs)
    logger.debug(str(payload))

    private_key = base64.b64decode(self.private_key)
    return crypt.make_signed_jwt(crypt.Signer.from_string(
        private_key, self.private_key_password), payload)

# Only used in verify_id_token(), which is always calling to the same URI
# for the certs. 
開發者ID:mortcanty,項目名稱:earthengine,代碼行數:21,代碼來源:client.py

示例2: _generate_assertion

# 需要導入模塊: from oauth2client import crypt [as 別名]
# 或者: from oauth2client.crypt import make_signed_jwt [as 別名]
def _generate_assertion(self):
      """Generate the assertion that will be used in the request."""
      now = long(time.time())
      payload = {
          'aud': self.token_uri,
          'scope': self.scope,
          'iat': now,
          'exp': now + SignedJwtAssertionCredentials.MAX_TOKEN_LIFETIME_SECS,
          'iss': self.service_account_name
      }
      payload.update(self.kwargs)
      logger.debug(str(payload))

      private_key = base64.b64decode(self.private_key)
      return crypt.make_signed_jwt(crypt.Signer.from_string(
          private_key, self.private_key_password), payload)

  # Only used in verify_id_token(), which is always calling to the same URI
  # for the certs. 
開發者ID:splunk,項目名稱:splunk-ref-pas-code,代碼行數:21,代碼來源:client.py

示例3: _GenerateAssertion

# 需要導入模塊: from oauth2client import crypt [as 別名]
# 或者: from oauth2client.crypt import make_signed_jwt [as 別名]
def _GenerateAssertion(self):
    """Generates the signed assertion that will be used in the request.

    Returns:
      string, signed Json Web Token (JWT) assertion.
    """
    now = int(time.time())
    payload = {
        'aud': RpcHelper.TOKEN_ENDPOINT,
        'scope': 'https://www.googleapis.com/auth/identitytoolkit',
        'iat': now,
        'exp': now + RpcHelper.MAX_TOKEN_LIFETIME_SECS,
        'iss': self.service_account_email
    }
    return crypt.make_signed_jwt(
        crypt.Signer.from_string(self.service_account_key),
        payload) 
開發者ID:google,項目名稱:identity-toolkit-python-client,代碼行數:19,代碼來源:rpchelper.py

示例4: _create_token

# 需要導入模塊: from oauth2client import crypt [as 別名]
# 或者: from oauth2client.crypt import make_signed_jwt [as 別名]
def _create_token(self, additional_claims=None):
        now = client._UTCNOW()
        lifetime = datetime.timedelta(seconds=self._MAX_TOKEN_LIFETIME_SECS)
        expiry = now + lifetime
        payload = {
            'iat': _datetime_to_secs(now),
            'exp': _datetime_to_secs(expiry),
            'iss': self._service_account_email,
            'sub': self._service_account_email
        }
        payload.update(self._kwargs)
        if additional_claims is not None:
            payload.update(additional_claims)
        jwt = crypt.make_signed_jwt(self._signer, payload,
                                    key_id=self._private_key_id)
        return jwt.decode('ascii'), expiry 
開發者ID:fniephaus,項目名稱:alfred-gmail,代碼行數:18,代碼來源:service_account.py

示例5: _generate_assertion

# 需要導入模塊: from oauth2client import crypt [as 別名]
# 或者: from oauth2client.crypt import make_signed_jwt [as 別名]
def _generate_assertion(self):
        """Generate the assertion that will be used in the request."""
        now = int(time.time())
        payload = {
            'aud': self.token_uri,
            'scope': self.scope,
            'iat': now,
            'exp': now + SignedJwtAssertionCredentials.MAX_TOKEN_LIFETIME_SECS,
            'iss': self.service_account_name
        }
        payload.update(self.kwargs)
        logger.debug(str(payload))

        private_key = base64.b64decode(self.private_key)
        return crypt.make_signed_jwt(crypt.Signer.from_string(
            private_key, self.private_key_password), payload)

# Only used in verify_id_token(), which is always calling to the same URI
# for the certs. 
開發者ID:jmankoff,項目名稱:data,代碼行數:21,代碼來源:client.py

示例6: _generate_assertion

# 需要導入模塊: from oauth2client import crypt [as 別名]
# 或者: from oauth2client.crypt import make_signed_jwt [as 別名]
def _generate_assertion(self):
        """Generate the assertion that will be used in the request."""
        now = int(time.time())
        payload = {
            'aud': self.token_uri,
            'scope': self._scopes,
            'iat': now,
            'exp': now + self.MAX_TOKEN_LIFETIME_SECS,
            'iss': self._service_account_email,
        }
        payload.update(self._kwargs)
        return crypt.make_signed_jwt(self._signer, payload,
                                     key_id=self._private_key_id) 
開發者ID:Deltares,項目名稱:aqua-monitor,代碼行數:15,代碼來源:service_account.py

示例7: _create_token

# 需要導入模塊: from oauth2client import crypt [as 別名]
# 或者: from oauth2client.crypt import make_signed_jwt [as 別名]
def _create_token(self, additional_claims=None):
        now = _UTCNOW()
        expiry = now + datetime.timedelta(seconds=self._MAX_TOKEN_LIFETIME_SECS)
        payload = {
            'iat': _datetime_to_secs(now),
            'exp': _datetime_to_secs(expiry),
            'iss': self._service_account_email,
            'sub': self._service_account_email
        }
        payload.update(self._kwargs)
        if additional_claims is not None:
            payload.update(additional_claims)
        jwt = crypt.make_signed_jwt(self._signer, payload,
                                    key_id=self._private_key_id)
        return jwt.decode('ascii'), expiry 
開發者ID:Deltares,項目名稱:aqua-monitor,代碼行數:17,代碼來源:service_account.py

示例8: _create_signed_jwt

# 需要導入模塊: from oauth2client import crypt [as 別名]
# 或者: from oauth2client.crypt import make_signed_jwt [as 別名]
def _create_signed_jwt(self):
        private_key = datafile('privatekey.' + self.format_)
        signer = self.signer.from_string(private_key)
        audience = 'some_audience_address@testing.gserviceaccount.com'
        now = int(time.time())

        return crypt.make_signed_jwt(signer, {
            'aud': audience,
            'iat': now,
            'exp': now + 300,
            'user': 'billy bob',
            'metadata': {'meta': 'data'},
        }) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:15,代碼來源:test_jwt.py

示例9: test_verify_id_token_bad_tokens

# 需要導入模塊: from oauth2client import crypt [as 別名]
# 或者: from oauth2client.crypt import make_signed_jwt [as 別名]
def test_verify_id_token_bad_tokens(self):
        private_key = datafile('privatekey.' + self.format_)

        # Wrong number of segments
        self._check_jwt_failure('foo', 'Wrong number of segments')

        # Not json
        self._check_jwt_failure('foo.bar.baz', 'Can\'t parse token')

        # Bad signature
        jwt = b'.'.join([b'foo',
                         _helpers._urlsafe_b64encode('{"a":"b"}'),
                         b'baz'])
        self._check_jwt_failure(jwt, 'Invalid token signature')

        # No expiration
        signer = self.signer.from_string(private_key)
        audience = ('https:#www.googleapis.com/auth/id?client_id='
                    'external_public_key@testing.gserviceaccount.com')
        jwt = crypt.make_signed_jwt(signer, {
            'aud': audience,
            'iat': time.time(),
        })
        self._check_jwt_failure(jwt, 'No exp field in token')

        # No issued at
        jwt = crypt.make_signed_jwt(signer, {
            'aud': 'audience',
            'exp': time.time() + 400,
        })
        self._check_jwt_failure(jwt, 'No iat field in token')

        # Too early
        jwt = crypt.make_signed_jwt(signer, {
            'aud': 'audience',
            'iat': time.time() + 301,
            'exp': time.time() + 400,
        })
        self._check_jwt_failure(jwt, 'Token used too early')

        # Too late
        jwt = crypt.make_signed_jwt(signer, {
            'aud': 'audience',
            'iat': time.time() - 500,
            'exp': time.time() - 301,
        })
        self._check_jwt_failure(jwt, 'Token used too late')

        # Wrong target
        jwt = crypt.make_signed_jwt(signer, {
            'aud': 'somebody else',
            'iat': time.time(),
            'exp': time.time() + 300,
        })
        self._check_jwt_failure(jwt, 'Wrong recipient') 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:57,代碼來源:test_jwt.py


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