From 51434dd62df181679e04d2ffad9f21703e980888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B4natas=20Santos?= Date: Fri, 21 Aug 2026 16:52:55 -0300 Subject: [PATCH 1/5] feat: add get_profile_and_token_from_id_token for OIDC ID token exchange (4.16.0 backport) (#714) --- tests/test_sso.py | 34 ++++++++++++++++++++++++++++++++++ workos/__about__.py | 2 +- workos/sso.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/tests/test_sso.py b/tests/test_sso.py index 70649fd7b..6bec3bf67 100644 --- a/tests/test_sso.py +++ b/tests/test_sso.py @@ -424,6 +424,40 @@ def test_get_profile_and_token_returns_expected_workosprofile_object( assert profile_and_token.access_token == "01DY34ACQTM3B1CSX1YSZ8Z00D" assert profile_and_token.profile.to_dict() == mock_profile + def test_get_profile_and_token_from_id_token_returns_expected_workosprofile_object( + self, setup_with_client_id, mock_profile, mock_request_method + ): + response_dict = { + "profile": { + "object": "profile", + "id": mock_profile["id"], + "email": mock_profile["email"], + "first_name": mock_profile["first_name"], + "groups": mock_profile["groups"], + "organization_id": mock_profile["organization_id"], + "connection_id": mock_profile["connection_id"], + "connection_type": mock_profile["connection_type"], + "last_name": mock_profile["last_name"], + "idp_id": mock_profile["idp_id"], + "raw_attributes": { + "email": mock_profile["raw_attributes"]["email"], + "first_name": mock_profile["raw_attributes"]["first_name"], + "last_name": mock_profile["raw_attributes"]["last_name"], + "groups": mock_profile["raw_attributes"]["groups"], + }, + }, + "access_token": "01DY34ACQTM3B1CSX1YSZ8Z00D", + } + + mock_request_method("post", response_dict, 200) + + profile_and_token = self.sso.get_profile_and_token_from_id_token( + "eyJhbGciOiJSUzI1NiJ9.id.token", "org_01EHQMYV6MBK39QC5PZXHY59C3" + ) + + assert profile_and_token.access_token == "01DY34ACQTM3B1CSX1YSZ8Z00D" + assert profile_and_token.profile.to_dict() == mock_profile + def test_get_profile_and_token_without_first_name_or_last_name_returns_expected_workosprofile_object( self, setup_with_client_id, mock_magic_link_profile, mock_request_method ): diff --git a/workos/__about__.py b/workos/__about__.py index 4e19203ce..7664f6a00 100644 --- a/workos/__about__.py +++ b/workos/__about__.py @@ -12,7 +12,7 @@ __package_url__ = "https://github.com/workos-inc/workos-python" -__version__ = "4.15.0" +__version__ = "4.16.0" __author__ = "WorkOS" diff --git a/workos/sso.py b/workos/sso.py index cff8d9e35..d26cb2e8f 100644 --- a/workos/sso.py +++ b/workos/sso.py @@ -24,6 +24,8 @@ PROFILE_PATH = "sso/profile" OAUTH_GRANT_TYPE = "authorization_code" +TOKEN_EXCHANGE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:token-exchange" +ID_TOKEN_SUBJECT_TOKEN_TYPE = "urn:ietf:params:oauth:token-type:id_token" RESPONSE_LIMIT = 10 @@ -162,6 +164,39 @@ def get_profile_and_token(self, code): return WorkOSProfileAndToken.construct_from_response(response) + def get_profile_and_token_from_id_token(self, id_token, organization_id): + """Exchange an externally issued OIDC ID token for a Profile and Token + + For flows where the user authenticates natively with the identity + provider (for example a mobile app using MSAL against Microsoft Entra) + and no browser redirect occurs. The ID token is exchanged for the same + WorkOS profile the authorization code flow would return. The connection + must have an ID token trust configured for the token's issuer and + audience. + + Args: + id_token (str): The OIDC ID token issued to the client. + organization_id (str): The organization whose connection the ID + token should be validated against. + + Returns: + WorkOSProfileAndToken: WorkOSProfileAndToken object representing the User + """ + params = { + "client_id": workos.client_id, + "client_secret": workos.api_key, + "grant_type": TOKEN_EXCHANGE_GRANT_TYPE, + "subject_token": id_token, + "subject_token_type": ID_TOKEN_SUBJECT_TOKEN_TYPE, + "organization_id": organization_id, + } + + response = self.request_helper.request( + TOKEN_PATH, method=REQUEST_METHOD_POST, params=params + ) + + return WorkOSProfileAndToken.construct_from_response(response) + def get_connection(self, connection): """Gets details for a single Connection From 13df0cd677c96b082213de27e1637ed059b617fd Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Fri, 21 Aug 2026 15:59:37 -0400 Subject: [PATCH 2/5] fix: bump six to 1.16.0 for Python 3.12 compatibility six.moves fails to import on Python 3.12 before six 1.16.0, which broke test collection in the release workflow and blocked the v4.16.0 publish. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8d4c7cc39..564ff36f4 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ "flake8", "pytest==8.1.1", "pytest-cov==2.8.1", - "six==1.13.0", + "six==1.16.0", "black==22.3.0", "twine==4.0.2", "requests==2.30.0", From 38c3ba23a8635d050b47f4f8d24e89c48fb0cebd Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Fri, 21 Aug 2026 16:04:29 -0400 Subject: [PATCH 3/5] fix: bump twine to 5.1.1 for Python 3.12 compatibility twine 4.0.2 crashes at import with importlib_metadata >= 8 (KeyError: 'license'), which broke the Publish step of the v4.16.0 release workflow. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 564ff36f4..4a39e2051 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ "pytest-cov==2.8.1", "six==1.16.0", "black==22.3.0", - "twine==4.0.2", + "twine==5.1.1", "requests==2.30.0", "urllib3==2.0.2", ], From 7e0613a81a3cf47c85b38ae81ef47905c0cdc284 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Fri, 21 Aug 2026 16:08:01 -0400 Subject: [PATCH 4/5] fix: publish releases via PyPI Trusted Publishing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The TWINE_PASSWORD API token is stale (PyPI returns 403), and main already publishes via OIDC trusted publishing. Also pin Python 3.12 explicitly — the old ${{ matrix.python }} reference resolved to empty because no matrix exists, silently using the runner's system Python. --- .github/workflows/release.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d0df718b2..4ac0be150 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,11 +15,14 @@ jobs: test: name: Publish to PyPI runs-on: ubuntu-latest + permissions: + id-token: write + contents: read steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: - python-version: ${{ matrix.python }} + python-version: "3.12" cache: "pip" cache-dependency-path: setup.py @@ -31,11 +34,11 @@ jobs: run: | python -m pytest - - name: Publish - env: - TWINE_NON_INTERACTIVE: true - TWINE_USERNAME: "__token__" - TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} + - name: Build run: | python setup.py sdist bdist_wheel - twine upload dist/* --skip-existing + + - name: Publish + uses: pypa/gh-action-pypi-publish@release/v1 + with: + skip-existing: true From 494f4b4d56b88384d0736a99e3878a8f556a13f4 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Fri, 21 Aug 2026 16:09:53 -0400 Subject: [PATCH 5/5] fix: install setuptools before building Python 3.12 no longer bundles setuptools; the toolcache interpreter pinned by setup-python fails on 'python setup.py' without it. --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4ac0be150..91e03b401 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,6 +36,7 @@ jobs: - name: Build run: | + pip install --upgrade setuptools wheel python setup.py sdist bdist_wheel - name: Publish