Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPX: add send method #554

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions authlib/integrations/httpx_client/oauth2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ async def stream(self, method, url, withhold_token=False, auth=USE_CLIENT_DEFAUL
method, url, auth=auth, **kwargs) as resp:
yield resp

def send(self, req, withhold_token=False, auth=USE_CLIENT_DEFAULT, **kwargs):
if not withhold_token and auth is USE_CLIENT_DEFAULT:
if not self.token:
raise MissingTokenError()

self.ensure_active_token(self.token)
Copy link
Author

@lspgn lspgn Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing with the following fixes the issue but not sure about the solution

            loop = asyncio.get_running_loop()
            asyncio.ensure_future(self.ensure_active_token(self.token), loop=loop)


auth = self.token_auth

return super(AsyncOAuth2Client, self).send(req, auth=auth, **kwargs)

async def ensure_active_token(self, token):
async with self._token_refresh_lock:
if self.token.is_expired():
Expand Down
Loading