示例#1
0
    def __init__(self, app, tenant_id=None):
        if not app.project_id:
            raise ValueError(
                """A project ID is required to access the auth service.
            1. Use a service account credential, or
            2. set the project ID explicitly via Firebase App options, or
            3. set the project ID via the GOOGLE_CLOUD_PROJECT environment variable."""
            )

        credential = app.credential.get_credential()
        version_header = 'Python/Admin/{0}'.format(firebase_admin.__version__)
        timeout = app.options.get('httpTimeout',
                                  _http_client.DEFAULT_TIMEOUT_SECONDS)
        http_client = _http_client.JsonHttpClient(
            credential=credential,
            headers={'X-Client-Version': version_header},
            timeout=timeout)

        self._tenant_id = tenant_id
        self._token_generator = _token_gen.TokenGenerator(app, http_client)
        self._token_verifier = _token_gen.TokenVerifier(app)
        self._user_manager = _user_mgt.UserManager(http_client, app.project_id,
                                                   tenant_id)
        self._provider_manager = _auth_providers.ProviderConfigClient(
            http_client, app.project_id, tenant_id)
示例#2
0
 def test_retry_on_503(self, httpserver):
     httpserver.serve_content({}, 503)
     client = _http_client.JsonHttpClient(
         credential=testutils.MockGoogleCredential(),
         base_url=httpserver.url)
     with pytest.raises(requests.exceptions.HTTPError) as excinfo:
         client.request('get', '/')
     assert excinfo.value.response.status_code == 503
     assert len(httpserver.requests) == 5
示例#3
0
 def __init__(self, app):
     project_id = app.project_id
     if not project_id:
         raise ValueError(
             'Project ID is required to access Cloud Messaging service. Either set the'
             ' projectId option, or use service account credentials. Alternatively, set the '
             'GCLOUD_PROJECT environment variable.')
     self._fcm_url = _MessagingService.FCM_URL.format(project_id)
     self._client = _http_client.JsonHttpClient(credential=app.credential.get_credential())
示例#4
0
 def __init__(self, app):
     self._project_id = app.project_id
     if not self._project_id:
         raise ValueError(
             'Project ID is required to access ML service. Either set the '
             'projectId option, or use service account credentials.')
     self._project_url = _MLService.PROJECT_URL.format(self._project_id)
     ml_headers = {
         'X-FIREBASE-CLIENT': 'fire-admin-python/{0}'.format(firebase_admin.__version__),
     }
     self._client = _http_client.JsonHttpClient(
         credential=app.credential.get_credential(),
         headers=ml_headers,
         base_url=self._project_url)
     self._operation_client = _http_client.JsonHttpClient(
         credential=app.credential.get_credential(),
         headers=ml_headers,
         base_url=_MLService.OPERATION_URL)
示例#5
0
 def __init__(self, app):
     project_id = app.project_id
     if not project_id:
         raise ValueError(
             'Project ID is required to access Instance ID service. Either set the projectId '
             'option, or use service account credentials. Alternatively, set the '
             'GCLOUD_PROJECT environment variable.')
     self._project_id = project_id
     self._client = _http_client.JsonHttpClient(
         credential=app.credential.get_credential(), base_url=_IID_SERVICE_URL)
示例#6
0
 def __init__(self, app):
     credential = app.credential.get_credential()
     version_header = 'Python/Admin/{0}'.format(firebase_admin.__version__)
     client = _http_client.JsonHttpClient(
         credential=credential,
         base_url=self.ID_TOOLKIT_URL,
         headers={'X-Client-Version': version_header})
     self._token_generator = _token_gen.TokenGenerator(app, client)
     self._token_verifier = _token_gen.TokenVerifier(app)
     self._user_manager = _user_mgt.UserManager(client)
示例#7
0
 def __init__(self, app):
     project_id = app.project_id
     if not project_id:
         raise ValueError(
             'Project ID is required to access the Firebase Project Management Service. Either '
             'set the projectId option, or use service account credentials. Alternatively, set '
             'the GOOGLE_CLOUD_PROJECT environment variable.')
     self._project_id = project_id
     self._client = _http_client.JsonHttpClient(
         credential=app.credential.get_credential(),
         base_url=_ProjectManagementService.BASE_URL)
     self._timeout = app.options.get('httpTimeout')
示例#8
0
 def __init__(self, app):
     credential = app.credential.get_credential()
     version_header = 'Python/Admin/{0}'.format(firebase_admin.__version__)
     base_url = '{0}/projects/{1}'.format(self.TENANT_MGT_URL,
                                          app.project_id)
     self.app = app
     self.client = _http_client.JsonHttpClient(
         credential=credential,
         base_url=base_url,
         headers={'X-Client-Version': version_header})
     self.tenant_clients = {}
     self.lock = threading.RLock()
示例#9
0
 def test_retry_on_500(self, httpserver, method):
     httpserver.serve_content({}, 500)
     client = _http_client.JsonHttpClient(
         credential=testutils.MockGoogleCredential(),
         base_url=httpserver.url)
     body = None
     if method in self.ENTITY_ENCLOSING_METHODS:
         body = {'key': 'value'}
     with pytest.raises(requests.exceptions.HTTPError) as excinfo:
         client.request(method, '/', json=body)
     assert excinfo.value.response.status_code == 500
     assert len(httpserver.requests) == 5
示例#10
0
 def __init__(self, app):
     project_id = app.project_id
     if not project_id:
         raise ValueError(
             'Project ID is required to access Cloud Messaging service. Either set the '
             'projectId option, or use service account credentials. Alternatively, set the '
             'GOOGLE_CLOUD_PROJECT environment variable.')
     self._fcm_url = _MessagingService.FCM_URL.format(project_id)
     self._client = _http_client.JsonHttpClient(
         credential=app.credential.get_credential())
     self._timeout = app.options.get('httpTimeout')
     self._client_version = 'fire-admin-python/{0}'.format(
         firebase_admin.__version__)
 def __init__(self, app):
     project_id = app.project_id
     if not project_id:
         raise ValueError(
             'Project ID is required to access the Firebase Project Management Service. Either '
             'set the projectId option, or use service account credentials. Alternatively, set '
             'the GOOGLE_CLOUD_PROJECT environment variable.')
     self._project_id = project_id
     version_header = 'Python/Admin/{0}'.format(firebase_admin.__version__)
     self._client = _http_client.JsonHttpClient(
         credential=app.credential.get_credential(),
         base_url=_ProjectManagementService.BASE_URL,
         headers={'X-Client-Version': version_header})
     self._timeout = app.options.get('httpTimeout')
    def __init__(self, app, tenant_id=None):
        if not app.project_id:
            raise ValueError(
                """A project ID is required to access the auth service.
            1. Use a service account credential, or
            2. set the project ID explicitly via Firebase App options, or
            3. set the project ID via the GOOGLE_CLOUD_PROJECT environment variable."""
            )

        credential = None
        version_header = 'Python/Admin/{0}'.format(firebase_admin.__version__)
        timeout = app.options.get('httpTimeout',
                                  _http_client.DEFAULT_TIMEOUT_SECONDS)
        # Non-default endpoint URLs for emulator support are set in this dict later.
        endpoint_urls = {}
        self.emulated = False

        # If an emulator is present, check that the given value matches the expected format and set
        # endpoint URLs to use the emulator. Additionally, use a fake credential.
        emulator_host = _auth_utils.get_emulator_host()
        if emulator_host:
            base_url = 'http://{0}/identitytoolkit.googleapis.com'.format(
                emulator_host)
            endpoint_urls['v1'] = base_url + '/v1'
            endpoint_urls['v2beta1'] = base_url + '/v2beta1'
            credential = _utils.EmulatorAdminCredentials()
            self.emulated = True
        else:
            # Use credentials if provided
            credential = app.credential.get_credential()

        http_client = _http_client.JsonHttpClient(
            credential=credential,
            headers={'X-Client-Version': version_header},
            timeout=timeout)

        self._tenant_id = tenant_id
        self._token_generator = _token_gen.TokenGenerator(
            app, http_client, url_override=endpoint_urls.get('v1'))
        self._token_verifier = _token_gen.TokenVerifier(app)
        self._user_manager = _user_mgt.UserManager(
            http_client,
            app.project_id,
            tenant_id,
            url_override=endpoint_urls.get('v1'))
        self._provider_manager = _auth_providers.ProviderConfigClient(
            http_client,
            app.project_id,
            tenant_id,
            url_override=endpoint_urls.get('v2beta1'))
示例#13
0
 def __init__(self, app):
     project_id = app.project_id
     if not project_id:
         raise ValueError(
             'Project ID is required to access Cloud Messaging service. Either set the '
             'projectId option, or use service account credentials. Alternatively, set the '
             'GOOGLE_CLOUD_PROJECT environment variable.')
     self._fcm_url = _MessagingService.FCM_URL.format(project_id)
     self._fcm_headers = {
         'X-GOOG-API-FORMAT-VERSION': '2',
         'X-FIREBASE-CLIENT': 'fire-admin-python/{0}'.format(firebase_admin.__version__),
     }
     self._client = _http_client.JsonHttpClient(credential=app.credential.get_credential())
     self._timeout = app.options.get('httpTimeout')
     self._transport = _auth.authorized_http(app.credential.get_credential())
示例#14
0
 def __init__(self, app):
     project_id = app.project_id
     if not project_id:
         raise ValueError(
             'Project ID is required to access Instance ID service. Either set the projectId '
             'option, or use service account credentials. Alternatively, set the '
             'GCLOUD_PROJECT environment variable.')
     elif not isinstance(project_id, six.string_types):
         raise ValueError(
             'Invalid project ID: "{0}". project ID must be a string.'.
             format(project_id))
     self._project_id = project_id
     self._client = _http_client.JsonHttpClient(
         credential=app.credential.get_credential(),
         base_url=_IID_SERVICE_URL)
示例#15
0
    def __init__(self, app):
        credential = app.credential.get_credential()
        version_header = 'Python/Admin/{0}'.format(firebase_admin.__version__)

        if not app.project_id:
            raise ValueError("""Project ID is required to access the auth service.
            1. Use a service account credential, or
            2. set the project ID explicitly via Firebase App options, or
            3. set the project ID via the GOOGLE_CLOUD_PROJECT environment variable.""")

        client = _http_client.JsonHttpClient(
            credential=credential, base_url=self.ID_TOOLKIT_URL + app.project_id,
            headers={'X-Client-Version': version_header})
        self._token_generator = _token_gen.TokenGenerator(app, client)
        self._token_verifier = _token_gen.TokenVerifier(app)
        self._user_manager = _user_mgt.UserManager(client)