diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index fdf77ea8a7..6632ef7006 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -3292,7 +3292,6 @@ class SAMLAuthBackendTest(SocialAuthBase): class AppleAuthMixin: - BACKEND_CLASS = AppleAuthBackend CLIENT_KEY_SETTING = "SOCIAL_AUTH_APPLE_KEY" AUTHORIZATION_URL = "https://appleid.apple.com/auth/authorize" ACCESS_TOKEN_URL = "https://appleid.apple.com/auth/token" @@ -3329,6 +3328,7 @@ class AppleAuthMixin: class AppleIdAuthBackendTest(AppleAuthMixin, SocialAuthBase): + BACKEND_CLASS = AppleAuthBackend LOGIN_URL = "/accounts/login/social/apple" SIGNUP_URL = "/accounts/register/social/apple" @@ -3462,6 +3462,7 @@ class AppleIdAuthBackendTest(AppleAuthMixin, SocialAuthBase): class AppleAuthBackendNativeFlowTest(AppleAuthMixin, SocialAuthBase): + BACKEND_CLASS = AppleAuthBackend SIGNUP_URL = "/complete/apple/" LOGIN_URL = "/complete/apple/" diff --git a/zproject/backends.py b/zproject/backends.py index b8f7bbb756..76b7d4994f 100644 --- a/zproject/backends.py +++ b/zproject/backends.py @@ -1630,7 +1630,7 @@ def redirect_deactivated_user_to_login(realm: Realm, email: str) -> HttpResponse def social_associate_user_helper( - backend: BaseAuth, return_data: dict[str, Any], *args: Any, **kwargs: Any + backend: "SocialAuthMixin", return_data: dict[str, Any], *args: Any, **kwargs: Any ) -> HttpResponse | UserProfile | None: """Responsible for doing the Zulip account lookup and validation parts of the Zulip social auth pipeline (similar to the authenticate() @@ -1790,6 +1790,7 @@ def social_auth_associate_user( later stages of settings.SOCIAL_AUTH_PIPELINE, such as social_auth_finish, as kwargs. """ + assert isinstance(backend, SocialAuthMixin) partial_token = backend.strategy.request_data().get("partial_token") return_data: dict[str, Any] = {} user_profile = social_associate_user_helper(backend, return_data, *args, **kwargs) @@ -2143,15 +2144,15 @@ class GitHubAuthBackend(SocialAuthMixin, GithubOAuth2): **kwargs, ) elif team_id is not None: - backend = GithubTeamOAuth2(self.strategy, self.redirect_uri) + team_backend = GithubTeamOAuth2(self.strategy, self.redirect_uri) try: - return backend.user_data(access_token, *args, **kwargs) + return team_backend.user_data(access_token, *args, **kwargs) except AuthFailed: return dict(auth_failed_reason="GitHub user is not member of required team") elif org_name is not None: - backend = GithubOrganizationOAuth2(self.strategy, self.redirect_uri) + organization_backend = GithubOrganizationOAuth2(self.strategy, self.redirect_uri) try: - return backend.user_data(access_token, *args, **kwargs) + return organization_backend.user_data(access_token, *args, **kwargs) except AuthFailed: return dict(auth_failed_reason="GitHub user is not member of required organization")