Skip to content

feat: add async client base, AsyncHTTPClient, AsyncDescopeClient, and async TOTP#1562

Draft
LioriE wants to merge 12 commits into
mainfrom
feat/poc-async-base-and-totp
Draft

feat: add async client base, AsyncHTTPClient, AsyncDescopeClient, and async TOTP#1562
LioriE wants to merge 12 commits into
mainfrom
feat/poc-async-base-and-totp

Conversation

@LioriE

@LioriE LioriE commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Introduced _ClientBase and _AuthBase to extract shared sync/async logic
  • Added AsyncHTTPClient with httpx.AsyncClient for non-blocking HTTP
  • Added AsyncDescopeClient as the async counterpart to DescopeClient
  • Added async TOTP support via AsyncTOTP backed by a shared _TOTPBase
  • Refactored DescopeClient and TOTP to reuse the new base classes

Status

Draft / POC — async infrastructure is in place; remaining auth methods need to be ported to async.

Test plan

  • tests/test_async_http_client.py — AsyncHTTPClient unit tests
  • tests/test_descope_client_parity.py — sync/async client behaviour parity
  • tests/test_totp_parity.py — sync/async TOTP parity

Comment thread tests/test_descope_client_unified.py Fixed
Comment thread tests/test_descope_client_parity.py Outdated
Comment thread tests/test_descope_client_parity.py Outdated
@LioriE LioriE force-pushed the feat/poc-async-base-and-totp branch from 46a82d0 to 99839cc Compare June 7, 2026 13:03
@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown

Coverage report

The coverage rate went from 98.31% to 98.23% ⬇️

97.4% of new lines are covered.

Diff Coverage details (click to unfold)

descope/_client_base.py

94.11% of new lines are covered (94.11% of the complete file).
Missing lines: 54, 124, 125, 126, 175, 225

descope/_auth_base.py

87.5% of new lines are covered (92.3% of the complete file).
Missing lines: 9

descope/init.py

100% of new lines are covered (100% of the complete file).

descope/authmethod/totp.py

100% of new lines are covered (100% of the complete file).

descope/http_client_async.py

100% of new lines are covered (100% of the complete file).

descope/http_client.py

100% of new lines are covered (100% of the complete file).

descope/descope_client.py

100% of new lines are covered (98.18% of the complete file).

descope/descope_client_async.py

96.1% of new lines are covered (96.1% of the complete file).
Missing lines: 89, 101, 104

descope/_http_base.py

66.66% of new lines are covered (81.81% of the complete file).
Missing lines: 8, 22

descope/authmethod/_totp_base.py

100% of new lines are covered (100% of the complete file).

descope/_http_client_base.py

100% of new lines are covered (100% of the complete file).

descope/authmethod/totp_async.py

100% of new lines are covered (100% of the complete file).

Comment thread descope/_http_client_base.py Dismissed
Comment thread descope/_http_client_base.py
LioriE and others added 4 commits June 8, 2026 18:21
Move PUBLIC_KEY_DICT, VALID_REFRESH_TOKEN, VALID_SESSION_TOKEN, and
EXPIRED_SESSION_TOKEN from individual test files into testutils.py.
Move assert_http_called into conftest.py. Replace old test files with
the unified sync/async parity versions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace ~45 three-line dash-banner comment blocks across 8 files with
nothing — class names, method names, and docstrings already describe
what those banners labelled. The only banner-style block kept is the
SOCKS-proxy workaround doc in conftest.py, which is real documentation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread descope/_auth_base.py
Comment thread descope/_http_base.py
@LioriE LioriE requested a review from omercnet June 9, 2026 10:35
@omercnet

omercnet commented Jun 9, 2026

Copy link
Copy Markdown
Member

@shuni review this async implementation will it scale to all other methods?

@shuni-bot

shuni-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🐕 Review complete — View session on Shuni Portal 🐾

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni's Review

POC that extracts shared sync/async base classes and adds AsyncHTTPClient, AsyncDescopeClient, and async TOTP. Clean refactor — the base-class extraction preserves behaviour and sync/async parity is faithful (verified against Auth methods).

Sniffed out 3 issues:

  • 1 🟡 MEDIUM: async validate/refresh path runs blocking sync I/O on the event loop
  • 2 🟢 LOW: committed sandbox workaround in conftest; verbose put parity gap

No bugs that break — good bones for a POC! Woof!

Comment thread descope/descope_client_async.py
Comment thread tests/conftest.py
params=params,
)
)
self._raise_from_response(response)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 LOW: put skips the if self.verbose: self._last_response_var.set(...) capture that get/post/patch/delete all do, so get_last_response() returns a stale response after a PUT. (The sync HTTPClient.put has the same gap, so this preserves parity — but since this is new code it's a cheap spot to fix both.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@omercnet is this intentional?

@LioriE

LioriE commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@shuni follow the example set in this PR
implement the changes on the other auth methods and the management methods.
including testing

follow conventions and patterns set in this PR.

perform this in another branch and open a pull request to this branch.

@shuni-bot

shuni-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🐕 Uh oh! I ran into an error.

View failed run

Please check the logs for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants