MCPcopy Create free account
hub / github.com/authlib/authlib / AsyncOAuth2Client

Class AsyncOAuth2Client

authlib/integrations/httpx_client/oauth2_client.py:67–212  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65
66
67class AsyncOAuth2Client(_OAuth2Client, httpx2.AsyncClient):
68 SESSION_REQUEST_PARAMS = HTTPX_CLIENT_KWARGS
69
70 client_auth_class = OAuth2ClientAuth
71 token_auth_class = OAuth2Auth
72 oauth_error_class = OAuthError
73
74 def __init__(
75 self,
76 client_id=None,
77 client_secret=None,
78 token_endpoint_auth_method=None,
79 revocation_endpoint_auth_method=None,
80 scope=None,
81 redirect_uri=None,
82 token=None,
83 token_placement="header",
84 update_token=None,
85 leeway=60,
86 **kwargs,
87 ):
88 # extract httpx2.Client kwargs
89 client_kwargs = self._extract_session_request_params(kwargs)
90 httpx2.AsyncClient.__init__(self, **client_kwargs)
91
92 # We use a Lock to synchronize coroutines to prevent
93 # multiple concurrent attempts to refresh the same token
94 self._token_refresh_lock = Lock()
95
96 _OAuth2Client.__init__(
97 self,
98 session=None,
99 client_id=client_id,
100 client_secret=client_secret,
101 token_endpoint_auth_method=token_endpoint_auth_method,
102 revocation_endpoint_auth_method=revocation_endpoint_auth_method,
103 scope=scope,
104 redirect_uri=redirect_uri,
105 token=token,
106 token_placement=token_placement,
107 update_token=update_token,
108 leeway=leeway,
109 **kwargs,
110 )
111
112 async def request(
113 self, method, url, withhold_token=False, auth=USE_CLIENT_DEFAULT, **kwargs
114 ):
115 if not withhold_token and auth is USE_CLIENT_DEFAULT:
116 if not self.token:
117 raise MissingTokenError()
118
119 await self.ensure_active_token(self.token)
120
121 auth = self.token_auth
122
123 return await super().request(method, url, auth=auth, **kwargs)
124

Calls

no outgoing calls