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


Python service_account.ServiceAccountCredentials方法代碼示例

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


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

示例1: _make_credentials

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def _make_credentials(self):
        private_key = datafile('privatekey.' + self.format_)
        signer = crypt.Signer.from_string(private_key)
        credentials = service_account.ServiceAccountCredentials(
            'some_account@example.com', signer,
            scopes='read+write',
            sub='joe@example.org')
        if self.format_ == 'pem':
            credentials._private_key_pkcs8_pem = private_key
        elif self.format_ == 'p12':
            credentials._private_key_pkcs12 = private_key
            credentials._private_key_password = (
                service_account._PASSWORD_DEFAULT)
        else:  # pragma: NO COVER
            raise ValueError('Unexpected format.')
        return credentials 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:18,代碼來源:test_jwt.py

示例2: test__to_json_override

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def test__to_json_override(self):
        signer = object()
        creds = service_account.ServiceAccountCredentials(
            'name@email.com', signer)
        self.assertEqual(creds._signer, signer)
        # Serialize over-ridden data (unrelated to ``creds``).
        to_serialize = {'unrelated': 'data'}
        serialized_str = creds._to_json([], to_serialize.copy())
        serialized_data = json.loads(serialized_str)
        expected_serialized = {
            '_class': 'ServiceAccountCredentials',
            '_module': 'oauth2client.service_account',
            'token_expiry': None,
        }
        expected_serialized.update(to_serialize)
        self.assertEqual(serialized_data, expected_serialized) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:18,代碼來源:test_service_account.py

示例3: setUp

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def setUp(self):
        self._m_request = Deferred()
        self._m_response = Mock(spec=treq.response._Response)
        self._m_response.code = 200
        self._m_response.headers = Headers()
        self._m_resp_text = Deferred()
        self._m_response.text.return_value = self._m_resp_text
        self.fcm = FCMv1(project_id="fcm_test")
        self.fcm._sender = Mock(spec=treq.request)
        self.fcm.svc_cred = Mock(spec=ServiceAccountCredentials)
        atoken = Mock()
        atoken.access_token = "access_token"
        self.fcm.svc_cred.get_access_token.return_value = atoken
        self.fcm._sender.return_value = self._m_request
        self.m_payload = {"ttl": 60, "data_message": "some content"}
        self._success = {
            u"name": (u'projects/fir-bridgetest/messages/'
                      u'0:1544652984769917%0aa51ebcf9fd7ecd')
        }
        self._failure = {
            u'error': {
                u'status': u'INVALID_ARGUMENT',
                u'message': (u'The registration token is not a valid '
                             u'FCM registration token'),
                u'code': 400,
                u'details': [
                    {
                        u'errorCode': u'INVALID_ARGUMENT',
                        u'@type': (u'type.googleapis.com/google.firebase'
                                   u'.fcm.v1.FcmError')},
                    {u'fieldViolations': [
                        {u'field': u'message.token',
                         u'description': (u'The registration token is not '
                                          u'a valid FCM registration token')}],
                        u'@type': u'type.googleapis.com/google.rpc.BadRequest'}
                ]
            }
        } 
開發者ID:mozilla-services,項目名稱:autopush,代碼行數:40,代碼來源:test_fcmclient.py

示例4: from_json

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def from_json(cls, json_data):
        # TODO(issue 388): eliminate the circularity that is the reason for
        #                  this non-top-level import.
        from oauth2client import service_account
        data = json.loads(_helpers._from_bytes(json_data))

        # We handle service_account.ServiceAccountCredentials since it is a
        # possible return type of GoogleCredentials.get_application_default()
        if (data['_module'] == 'oauth2client.service_account' and
                data['_class'] == 'ServiceAccountCredentials'):
            return service_account.ServiceAccountCredentials.from_json(data)
        elif (data['_module'] == 'oauth2client.service_account' and
                data['_class'] == '_JWTAccessCredentials'):
            return service_account._JWTAccessCredentials.from_json(data)

        token_expiry = _parse_expiry(data.get('token_expiry'))
        google_credentials = cls(
            data['access_token'],
            data['client_id'],
            data['client_secret'],
            data['refresh_token'],
            token_expiry,
            data['token_uri'],
            data['user_agent'],
            revoke_uri=data.get('revoke_uri', None))
        google_credentials.invalid = data['invalid']
        return google_credentials 
開發者ID:fniephaus,項目名稱:alfred-gmail,代碼行數:29,代碼來源:client.py

示例5: _get_bq_service

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def _get_bq_service(credentials=None, service_url=None):
    """Construct an authorized BigQuery service object."""

    assert credentials, 'Must provide ServiceAccountCredentials'

    http = credentials.authorize(Http())
    service = build(
        'bigquery',
        'v2',
        http=http,
        discoveryServiceUrl=service_url,
        cache_discovery=False
    )

    return service 
開發者ID:tylertreat,項目名稱:BigQuery-Python,代碼行數:17,代碼來源:client.py

示例6: _credentials

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def _credentials():
    """Import and return SignedJwtAssertionCredentials class"""
    from oauth2client.service_account import ServiceAccountCredentials

    return ServiceAccountCredentials 
開發者ID:tylertreat,項目名稱:BigQuery-Python,代碼行數:7,代碼來源:client.py

示例7: setUp

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def setUp(self):
        self.orig_signer = crypt.Signer
        self.orig_verifier = crypt.Verifier
        self.client_id = '123'
        self.service_account_email = 'dummy@google.com'
        self.private_key_id = 'ABCDEF'
        self.private_key = datafile('pem_from_pkcs12.pem')
        self.scopes = ['dummy_scope']
        self.signer = crypt.Signer.from_string(self.private_key)
        self.credentials = service_account.ServiceAccountCredentials(
            self.service_account_email,
            self.signer,
            private_key_id=self.private_key_id,
            client_id=self.client_id,
        ) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:17,代碼來源:test_service_account.py

示例8: _from_json_keyfile_name_helper

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def _from_json_keyfile_name_helper(payload, scopes=None,
                                       token_uri=None, revoke_uri=None):
        filehandle, filename = tempfile.mkstemp()
        os.close(filehandle)
        try:
            with open(filename, 'w') as file_obj:
                json.dump(payload, file_obj)
            return (
                service_account.ServiceAccountCredentials
                .from_json_keyfile_name(
                    filename, scopes=scopes, token_uri=token_uri,
                    revoke_uri=revoke_uri))
        finally:
            os.remove(filename) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:16,代碼來源:test_service_account.py

示例9: _from_p12_keyfile_helper

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def _from_p12_keyfile_helper(self, private_key_password=None, scopes='',
                                 token_uri=None, revoke_uri=None):
        service_account_email = 'name@email.com'
        filename = data_filename('privatekey.p12')
        with open(filename, 'rb') as file_obj:
            key_contents = file_obj.read()
        creds_from_filename = (
            service_account.ServiceAccountCredentials.from_p12_keyfile(
                service_account_email, filename,
                private_key_password=private_key_password,
                scopes=scopes, token_uri=token_uri, revoke_uri=revoke_uri))
        creds_from_file_contents = (
            service_account.ServiceAccountCredentials.from_p12_keyfile_buffer(
                service_account_email, six.BytesIO(key_contents),
                private_key_password=private_key_password,
                scopes=scopes, token_uri=token_uri, revoke_uri=revoke_uri))
        for creds in (creds_from_filename, creds_from_file_contents):
            self.assertIsInstance(
                creds, service_account.ServiceAccountCredentials)
            self.assertIsNone(creds.client_id)
            self.assertEqual(creds._service_account_email,
                             service_account_email)
            self.assertIsNone(creds._private_key_id)
            self.assertIsNone(creds._private_key_pkcs8_pem)
            self.assertEqual(creds._private_key_pkcs12, key_contents)
            if private_key_password is not None:
                self.assertEqual(creds._private_key_password,
                                 private_key_password)
            self.assertEqual(creds._scopes, ' '.join(scopes))
            self.assertEqual(creds.token_uri, token_uri)
            self.assertEqual(creds.revoke_uri, revoke_uri) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:33,代碼來源:test_service_account.py

示例10: _p12_not_implemented_helper

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def _p12_not_implemented_helper(self):
        service_account_email = 'name@email.com'
        filename = data_filename('privatekey.p12')
        with self.assertRaises(NotImplementedError):
            service_account.ServiceAccountCredentials.from_p12_keyfile(
                service_account_email, filename) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:8,代碼來源:test_service_account.py

示例11: test_create_scoped_required_with_scopes

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def test_create_scoped_required_with_scopes(self):
        signer = object()
        self.credentials = service_account.ServiceAccountCredentials(
            self.service_account_email,
            signer,
            scopes=self.scopes,
            private_key_id=self.private_key_id,
            client_id=self.client_id,
        )
        self.assertFalse(self.credentials.create_scoped_required()) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:12,代碼來源:test_service_account.py

示例12: test_create_scoped

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def test_create_scoped(self):
        new_credentials = self.credentials.create_scoped(self.scopes)
        self.assertNotEqual(self.credentials, new_credentials)
        self.assertIsInstance(new_credentials,
                              service_account.ServiceAccountCredentials)
        self.assertEqual('dummy_scope', new_credentials._scopes) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:8,代碼來源:test_service_account.py

示例13: test_create_delegated

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def test_create_delegated(self):
        signer = object()
        sub = 'foo@email.com'
        creds = service_account.ServiceAccountCredentials(
            'name@email.com', signer)
        self.assertNotIn('sub', creds._kwargs)
        delegated_creds = creds.create_delegated(sub)
        self.assertEqual(delegated_creds._kwargs['sub'], sub)
        # Make sure the original is unchanged.
        self.assertNotIn('sub', creds._kwargs) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:12,代碼來源:test_service_account.py

示例14: setUp

# 需要導入模塊: from oauth2client import service_account [as 別名]
# 或者: from oauth2client.service_account import ServiceAccountCredentials [as 別名]
def setUp(self):
        conf = AutopushConfig(
            hostname="localhost",
            statsd_host=None,
        )
        self.fcm_config = {'max_data': 32,
                           'ttl': 60,
                           'version': 1,
                           'dryrun': False,
                           'collapsekey': 'simplepush',
                           'creds': {
                               'fir-bridgetest': {
                                   'projectid': 'fir-bridgetest',
                                   # We specify 'None' here because we're
                                   # going to mock out the actual service
                                   # credential service.
                                   # This should be a path to a valid service
                                   # credential JSON file.
                                   'auth': None
                               }}}
        self._m_request = Deferred()
        self.response = Mock(spec=treq.response._Response)
        self.response.code = 200
        self.response.headers = Headers()
        self._m_resp_text = Deferred()
        self.response.text.return_value = self._m_resp_text
        self.response.content = json.dumps(
            {u'name': (u'projects/fir-bridgetest/messages/'
                       u'0:1510011451922224%7a0e7efbaab8b7cc')})
        self.client = fcmv1client.FCMv1(project_id="fir-bridgetest")
        self.client._sender = Mock()
        self.client.svc_cred = Mock(spec=ServiceAccountCredentials)
        self.client._sender.return_value = self._m_request
        self.router = FCMv1Router(conf, self.fcm_config, SinkMetrics())
        self.router.clients = {"fir-bridgetest": self.client}
        self.headers = {"content-encoding": "aesgcm",
                        "encryption": "test",
                        "encryption-key": "test"}
        # Payloads are Base64-encoded.
        self.notif = WebPushNotification(
            uaid=uuid.UUID(dummy_uaid),
            channel_id=uuid.UUID(dummy_chid),
            data="q60d6g",
            headers=self.headers,
            ttl=200,
            message_id=10,
        )
        self.notif.cleanup_headers()
        self.router_data = dict(
            router_data=dict(
                token="connect_data",
                app_id="fir-bridgetest")
        ) 
開發者ID:mozilla-services,項目名稱:autopush,代碼行數:55,代碼來源:test_router.py


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