Skip to content

Commit 90ea95f

Browse files
zzstoatzzclaude
andcommitted
add OAuth mixin for transparent session handling in Client/AsyncClient
incorporates the best aspects of PR MarshalX#640's mixin approach while keeping our async support, security module, and comprehensive test coverage. **key changes:** - add OAuthSessionMixin and AsyncOAuthSessionMixin to atproto_client - integrate mixins into Client and AsyncClient classes - override _invoke to transparently handle OAuth sessions with DPoP - add oauth_login(), oauth_logout(), export_oauth_session() methods - update codegen to auto-transform sync mixin to async **usage:** ```python from atproto_client import Client from atproto_oauth import OAuthClient # get OAuth session via OAuthClient (unchanged) oauth_client = OAuthClient(...) session = await oauth_client.handle_callback(code, state, iss) # use with Client - requests are now transparently authenticated client = Client( oauth_client_id='https://myapp.com/client-metadata.json', oauth_redirect_uri='https://myapp.com/callback', oauth_scope='atproto', ) client.oauth_login(session) # all existing methods work with OAuth session timeline = client.get_timeline() ``` **what this enables:** - seamless integration: existing client methods work with OAuth sessions - no manual DPoP proof generation for each request - automatic nonce rotation on PDS requests - session export/import for persistence 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent bd066ef commit 90ea95f

15 files changed

+573
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
atproto\_oauth.client
2+
=====================
3+
4+
.. automodule:: atproto_oauth.client
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
atproto\_oauth.dpop
2+
===================
3+
4+
.. automodule:: atproto_oauth.dpop
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
atproto\_oauth.exceptions
2+
=========================
3+
4+
.. automodule:: atproto_oauth.exceptions
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
atproto\_oauth.metadata
2+
=======================
3+
4+
.. automodule:: atproto_oauth.metadata
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
atproto\_oauth.models
2+
=====================
3+
4+
.. automodule:: atproto_oauth.models
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
atproto\_oauth.pkce
2+
===================
3+
4+
.. automodule:: atproto_oauth.pkce
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
atproto\_oauth.security
2+
=======================
3+
4+
.. automodule:: atproto_oauth.security
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
atproto\_oauth.stores.base
2+
==========================
3+
4+
.. automodule:: atproto_oauth.stores.base
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
atproto\_oauth.stores.memory
2+
============================
3+
4+
.. automodule:: atproto_oauth.stores.memory
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

packages/atproto_client/client/async_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from atproto_client.client.async_raw import AsyncClientRaw
1515
from atproto_client.client.methods_mixin import SessionMethodsMixin, TimeMethodsMixin
1616
from atproto_client.client.methods_mixin.headers import HeadersConfigurationMethodsMixin
17+
from atproto_client.client.methods_mixin.oauth import AsyncOAuthSessionMixin
1718
from atproto_client.client.methods_mixin.session import AsyncSessionDispatchMixin
1819
from atproto_client.client.session import Session, SessionEvent, SessionResponse
1920
from atproto_client.exceptions import LoginRequiredError
@@ -26,7 +27,12 @@
2627

2728

2829
class AsyncClient(
29-
AsyncSessionDispatchMixin, SessionMethodsMixin, TimeMethodsMixin, HeadersConfigurationMethodsMixin, AsyncClientRaw
30+
AsyncOAuthSessionMixin,
31+
AsyncSessionDispatchMixin,
32+
SessionMethodsMixin,
33+
TimeMethodsMixin,
34+
HeadersConfigurationMethodsMixin,
35+
AsyncClientRaw,
3036
):
3137
"""High-level client for XRPC of ATProto."""
3238

0 commit comments

Comments
 (0)