mirror of https://github.com/zulip/zulip.git
github: Pass proper parameters to authenticate.
Django tries to authenticate against all backends one by one. The authenticate() function of GitHub backend used to take *args and **kwargs arguments due to which it could be called against any set of arguments. Django uses arguments to differentiate authenticate() methods.
This commit is contained in:
parent
3bac73159a
commit
c5218fb584
|
@ -25,6 +25,9 @@ from zerver.lib.users import check_full_name
|
|||
from zerver.lib.request import JsonableError
|
||||
from zerver.lib.utils import check_subdomain, get_subdomain
|
||||
|
||||
from social_django.models import DjangoStorage
|
||||
from social_django.strategy import DjangoStrategy
|
||||
|
||||
def pad_method_dict(method_dict):
|
||||
# type: (Dict[Text, bool]) -> Dict[Text, bool]
|
||||
"""Pads an authentication methods dict to contain all auth backends
|
||||
|
@ -110,7 +113,43 @@ class SocialAuthMixin(ZulipAuthMixin):
|
|||
# type: (*Any, **Any) -> Text
|
||||
raise NotImplementedError
|
||||
|
||||
def authenticate(self, *args, **kwargs):
|
||||
def authenticate(self,
|
||||
realm_subdomain='', # type: Optional[Text]
|
||||
storage=None, # type: Optional[DjangoStorage]
|
||||
strategy=None, # type: Optional[DjangoStrategy]
|
||||
user=None, # type: Optional[Dict[str, Any]]
|
||||
return_data=None, # type: Optional[Dict[str, Any]]
|
||||
response=None, # type: Optional[Dict[str, Any]]
|
||||
backend=None # type: Optional[GithubOAuth2]
|
||||
):
|
||||
# type: (...) -> Optional[UserProfile]
|
||||
"""
|
||||
Django decides which `authenticate` to call by inspecting the
|
||||
arguments. So it's better to create `authenticate` function
|
||||
with well defined arguments.
|
||||
|
||||
Keeping this function separate so that it can easily be
|
||||
overridden.
|
||||
"""
|
||||
if user is None:
|
||||
user = {}
|
||||
|
||||
if return_data is None:
|
||||
return_data = {}
|
||||
|
||||
if response is None:
|
||||
response = {}
|
||||
|
||||
return self._common_authenticate(self,
|
||||
realm_subdomain=realm_subdomain,
|
||||
storage=storage,
|
||||
strategy=strategy,
|
||||
user=user,
|
||||
return_data=return_data,
|
||||
response=response,
|
||||
backend=backend)
|
||||
|
||||
def _common_authenticate(self, *args, **kwargs):
|
||||
# type: (*Any, **Any) -> Optional[UserProfile]
|
||||
return_data = kwargs.get('return_data', {})
|
||||
|
||||
|
@ -459,7 +498,7 @@ class GitHubAuthBackend(SocialAuthMixin, GithubOAuth2):
|
|||
we are doing individual, team or organization based GitHub
|
||||
authentication.
|
||||
The actual decision on authentication is done in
|
||||
SocialAuthMixin.authenticate().
|
||||
SocialAuthMixin._common_authenticate().
|
||||
"""
|
||||
kwargs['return_data'] = {}
|
||||
|
||||
|
|
Loading…
Reference in New Issue