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