[docs]classOAuth2Middleware(ClientMiddlewareType):""" Client middleware to add OAuth2 access tokens in the authorization header of HTTP requests. """def__init__(self,grant:OAuth2Grant):self.grant=grantasyncdef__call__(self,request:ClientRequest,handler:ClientHandlerType)->ClientResponse:awaitself.authenticate(request)response=awaithandler(request)returnresponse
[docs]asyncdefauthenticate(self,request:ClientRequest):""" Add the OAuth2 access token to the request's Authorization header. :param request: ClientRequest object :return: """request.headers.update(awaitself.grant.prepare_headers())