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