sources/oauth: cleanup clients, add type annotations
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
"""OAuth Base views"""
|
||||
from typing import Optional, Type
|
||||
|
||||
from django.http.request import HttpRequest
|
||||
|
||||
from passbook.sources.oauth.clients.base import BaseOAuthClient
|
||||
from passbook.sources.oauth.clients.oauth1 import OAuthClient
|
||||
from passbook.sources.oauth.clients.oauth2 import OAuth2Client
|
||||
@ -11,13 +13,15 @@ from passbook.sources.oauth.models import OAuthSource
|
||||
class OAuthClientMixin:
|
||||
"Mixin for getting OAuth client for a source."
|
||||
|
||||
request: HttpRequest # Set by View class
|
||||
|
||||
client_class: Optional[Type[BaseOAuthClient]] = None
|
||||
|
||||
def get_client(self, source: OAuthSource) -> BaseOAuthClient:
|
||||
def get_client(self, source: OAuthSource, **kwargs) -> BaseOAuthClient:
|
||||
"Get instance of the OAuth client for this source."
|
||||
if self.client_class is not None:
|
||||
# pylint: disable=not-callable
|
||||
return self.client_class(source)
|
||||
return self.client_class(source, self.request, **kwargs)
|
||||
if source.request_token_url:
|
||||
return OAuthClient(source)
|
||||
return OAuth2Client(source)
|
||||
return OAuthClient(source, self.request, **kwargs)
|
||||
return OAuth2Client(source, self.request, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user