From 07003ca756bb961bd540efdf35a70d206032cc5e Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Tue, 11 May 2021 20:20:59 -0400 Subject: [PATCH 1/2] Remove support for deprecated `project_id` parameter --- tests/conftest.py | 10 ---------- tests/test_client.py | 8 ++++---- tests/test_directory_sync.py | 3 +-- tests/test_passwordless.py | 2 +- tests/test_sso.py | 24 +----------------------- workos/__init__.py | 1 - workos/sso.py | 14 -------------- workos/utils/validation.py | 16 +++------------- 8 files changed, 10 insertions(+), 68 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index e003a5ae..9131d1c6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -24,21 +24,11 @@ def set_client_id(monkeypatch): monkeypatch.setattr(workos, "client_id", "client_b27needthisforssotemxo") -@pytest.fixture -def set_project_id(monkeypatch): - monkeypatch.setattr(workos, "project_id", "project_b27needthisforssotemxo") - - @pytest.fixture def set_api_key_and_client_id(set_api_key, set_client_id): pass -@pytest.fixture -def set_api_key_and_project_id(set_api_key, set_project_id): - pass - - @pytest.fixture def mock_request_method(monkeypatch): def inner(method, response_dict, status_code, headers=None): diff --git a/tests/test_client.py b/tests/test_client.py index 4523a5aa..1c94284f 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -13,7 +13,7 @@ def setup(self): client._portal = None client._sso = None - def test_initialize_sso(self, set_api_key_and_project_id): + def test_initialize_sso(self, set_api_key_and_client_id): assert bool(client.sso) def test_initialize_audit_log(self, set_api_key): @@ -28,14 +28,14 @@ def test_initialize_passwordless(self, set_api_key): def test_initialize_portal(self, set_api_key): assert bool(client.portal) - def test_initialize_sso_missing_api_key(self, set_project_id): + def test_initialize_sso_missing_api_key(self, set_client_id): with pytest.raises(ConfigurationException) as ex: client.sso message = str(ex) assert "api_key" in message - assert "project_id" not in message + assert "client_id" not in message def test_initialize_sso_missing_client_id(self, set_api_key): with pytest.raises(ConfigurationException) as ex: @@ -46,7 +46,7 @@ def test_initialize_sso_missing_client_id(self, set_api_key): assert "client_id" in message assert "api_key" not in message - def test_initialize_sso_missing_api_key_and_project_id(self): + def test_initialize_sso_missing_api_key_and_client_id(self): with pytest.raises(ConfigurationException) as ex: client.sso diff --git a/tests/test_directory_sync.py b/tests/test_directory_sync.py index 76e75292..2e944d80 100644 --- a/tests/test_directory_sync.py +++ b/tests/test_directory_sync.py @@ -104,8 +104,7 @@ def mock_directories(self): "state": "linked", "type": "gsuite directory", "name": "Ri Jeong Hyeok", - "bearer_token": None, - "project_id": "project_id", + "environment_id": "environment_id", "domain": "crashlandingonyou.com", } ], diff --git a/tests/test_passwordless.py b/tests/test_passwordless.py index e8308b18..08203d11 100644 --- a/tests/test_passwordless.py +++ b/tests/test_passwordless.py @@ -9,7 +9,7 @@ class TestPasswordless(object): @pytest.fixture(autouse=True) - def setup(self, set_api_key_and_project_id): + def setup(self, set_api_key_and_client_id): self.passwordless = Passwordless() @pytest.fixture diff --git a/tests/test_sso.py b/tests/test_sso.py index ee1de725..42ff1972 100644 --- a/tests/test_sso.py +++ b/tests/test_sso.py @@ -22,7 +22,7 @@ def setup_with_client_id(self, set_api_key_and_client_id): self.sso = SSO() @pytest.fixture - def setup_with_project_id(self, set_api_key_and_project_id): + def setup_with_client_id(self, set_api_key_and_client_id): self.provider = ConnectionType.GoogleOAuth self.customer_domain = "workos.com" self.redirect_uri = "https://localhost/auth/callback" @@ -194,28 +194,6 @@ def test_authorization_url_has_expected_query_params_with_domain_and_provider( "state": self.state, } - def test_authorization_url_supports_project_id_with_deprecation_warning( - self, setup_with_project_id - ): - with pytest.deprecated_call(): - authorization_url = self.sso.get_authorization_url( - domain=self.customer_domain, - provider=self.provider, - redirect_uri=self.redirect_uri, - state=self.state, - ) - - parsed_url = urlparse(authorization_url) - - assert dict(parse_qsl(parsed_url.query)) == { - "domain": self.customer_domain, - "provider": str(self.provider.value), - "client_id": workos.project_id, - "redirect_uri": self.redirect_uri, - "response_type": RESPONSE_TYPE_CODE, - "state": self.state, - } - def test_get_profile_returns_expected_workosprofile_object( self, setup_with_client_id, mock_profile, mock_request_method ): diff --git a/workos/__init__.py b/workos/__init__.py index ae4fc903..8158207b 100644 --- a/workos/__init__.py +++ b/workos/__init__.py @@ -4,6 +4,5 @@ from workos.client import client api_key = os.getenv("WORKOS_API_KEY") -project_id = os.getenv("WORKOS_PROJECT_ID") client_id = os.getenv("WORKOS_CLIENT_ID") base_api_url = "https://api.workos.com/" diff --git a/workos/sso.py b/workos/sso.py index 319df832..9f424bdc 100644 --- a/workos/sso.py +++ b/workos/sso.py @@ -80,13 +80,6 @@ def get_authorization_url( if state is not None: params["state"] = state - if workos.project_id is not None: - params["client_id"] = workos.project_id - warn( - "'project_id' is deprecated. Use 'client_id' instead.", - DeprecationWarning, - ) - prepared_request = Request( "GET", self.request_helper.generate_api_url(AUTHORIZATION_PATH), @@ -114,13 +107,6 @@ def get_profile(self, code): "grant_type": OAUTH_GRANT_TYPE, } - if workos.project_id is not None: - params["client_id"] = workos.project_id - warn( - "'project_id' is deprecated. Use 'client_id' instead.", - DeprecationWarning, - ) - response = self.request_helper.request( TOKEN_PATH, method=REQUEST_METHOD_POST, params=params ) diff --git a/workos/utils/validation.py b/workos/utils/validation.py index 139be8f4..23c8c85a 100644 --- a/workos/utils/validation.py +++ b/workos/utils/validation.py @@ -24,19 +24,9 @@ def decorator(fn): def wrapper(*args, **kwargs): missing_settings = [] - # Adding this to accept both client_id and project_id - # can remove once project_id is deprecated - if module_name == SSO_MODULE: - if not getattr(workos, "api_key", None): - missing_settings.append("api_key") - if not getattr(workos, "client_id", None) and not getattr( - workos, "project_id", None - ): - missing_settings.append("client_id") - else: - for setting in REQUIRED_SETTINGS_FOR_MODULE[module_name]: - if not getattr(workos, setting, None): - missing_settings.append(setting) + for setting in REQUIRED_SETTINGS_FOR_MODULE[module_name]: + if not getattr(workos, setting, None): + missing_settings.append(setting) if missing_settings: raise ConfigurationException( From 263ca5c71425f7bcd01635b59490420cf59f8a34 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Tue, 11 May 2021 20:23:25 -0400 Subject: [PATCH 2/2] Remove unneeded fixture --- tests/test_sso.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/test_sso.py b/tests/test_sso.py index 42ff1972..122987c2 100644 --- a/tests/test_sso.py +++ b/tests/test_sso.py @@ -21,15 +21,6 @@ def setup_with_client_id(self, set_api_key_and_client_id): self.sso = SSO() - @pytest.fixture - def setup_with_client_id(self, set_api_key_and_client_id): - self.provider = ConnectionType.GoogleOAuth - self.customer_domain = "workos.com" - self.redirect_uri = "https://localhost/auth/callback" - self.state = json.dumps({"things": "with_stuff"}) - - self.sso = SSO() - @pytest.fixture def mock_profile(self): return {