Exemplo n.º 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)
Exemplo n.º 2
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)
 def test_certificate_caching(self, user_mgt_app, httpserver):
     httpserver.serve_content(MOCK_PUBLIC_CERTS, 200, headers={'Cache-Control': 'max-age=3600'})
     verifier = _token_gen.TokenVerifier(user_mgt_app)
     verifier.cookie_verifier.cert_url = httpserver.url
     verifier.id_token_verifier.cert_url = httpserver.url
     verifier.verify_session_cookie(TEST_SESSION_COOKIE)
     assert len(httpserver.requests) == 1
     # Subsequent requests should not fetch certs from the server
     verifier.verify_session_cookie(TEST_SESSION_COOKIE)
     assert len(httpserver.requests) == 1
     verifier.verify_id_token(TEST_ID_TOKEN)
     assert len(httpserver.requests) == 1
    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'))
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def __init__(self, app):
     client = _AuthHTTPClient(app)
     self._token_generator = _token_gen.TokenGenerator(app, client)
     self._token_verifier = _token_gen.TokenVerifier(app)
     self._user_manager = _user_mgt.UserManager(client)