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

Class OAuth2Client

authlib/integrations/httpx_client/oauth2_client.py:211–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

209
210
211class OAuth2Client(_OAuth2Client, httpx.Client):
212 SESSION_REQUEST_PARAMS = HTTPX_CLIENT_KWARGS
213
214 client_auth_class = OAuth2ClientAuth
215 token_auth_class = OAuth2Auth
216 oauth_error_class = OAuthError
217
218 def __init__(
219 self,
220 client_id=None,
221 client_secret=None,
222 token_endpoint_auth_method=None,
223 revocation_endpoint_auth_method=None,
224 scope=None,
225 redirect_uri=None,
226 token=None,
227 token_placement="header",
228 update_token=None,
229 **kwargs,
230 ):
231 # extract httpx.Client kwargs
232 client_kwargs = self._extract_session_request_params(kwargs)
233 # app keyword was dropped!
234 app_value = client_kwargs.pop("app", None)
235 if app_value is not None:
236 client_kwargs["transport"] = httpx.WSGITransport(app=app_value)
237
238 httpx.Client.__init__(self, **client_kwargs)
239
240 _OAuth2Client.__init__(
241 self,
242 session=self,
243 client_id=client_id,
244 client_secret=client_secret,
245 token_endpoint_auth_method=token_endpoint_auth_method,
246 revocation_endpoint_auth_method=revocation_endpoint_auth_method,
247 scope=scope,
248 redirect_uri=redirect_uri,
249 token=token,
250 token_placement=token_placement,
251 update_token=update_token,
252 **kwargs,
253 )
254
255 @staticmethod
256 def handle_error(error_type, error_description):
257 raise OAuthError(error_type, error_description)
258
259 def request(
260 self, method, url, withhold_token=False, auth=USE_CLIENT_DEFAULT, **kwargs
261 ):
262 if not withhold_token and auth is USE_CLIENT_DEFAULT:
263 if not self.token:
264 raise MissingTokenError()
265
266 if not self.ensure_active_token(self.token):
267 raise InvalidTokenError()
268

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…