当前位置: 首页>>代码示例>>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;未经允许,请勿转载。