mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-30 19:43:47 +00:00 
			
		
		
		
	requirements: Update social-auth-core to latest version.
Uses git release as this version 3.4.0 is not released to pypi. This is required for removing some overriden functions of apple auth backend class AppleAuthBackend. With the update we also make following changes: * Fix full name being populated as "None None". c5c74f27dd that's included in update assigns first_name and last_name to None when no name is provided by apple. Due to this our code is filling return_data['full_name'] to 'None None'. This commit fixes it by making first and last name strings empty. * Remove decode_id_token override. Python social auth merged the PR we sent including the changes we made to decode_id_token function. So, now there is no necessity for the override. * Add _AUDIENCE setting in computed_settings.py. `decode_id_token` is dependent on this setting.
This commit is contained in:
		| @@ -18,7 +18,6 @@ import logging | ||||
| from abc import ABC, abstractmethod | ||||
| from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, TypeVar, Union, cast | ||||
|  | ||||
| import jwt | ||||
| import magic | ||||
| import ujson | ||||
| from decorator import decorator | ||||
| @@ -33,8 +32,6 @@ from django.shortcuts import render | ||||
| from django.urls import reverse | ||||
| from django.utils.translation import ugettext as _ | ||||
| from django_auth_ldap.backend import LDAPBackend, LDAPReverseEmailSearch, _LDAPUser, ldap_error | ||||
| from jwt.algorithms import RSAAlgorithm | ||||
| from jwt.exceptions import PyJWTError | ||||
| from lxml.etree import XMLSyntaxError | ||||
| from onelogin.saml2.errors import OneLogin_Saml2_Error | ||||
| from onelogin.saml2.response import OneLogin_Saml2_Response | ||||
| @@ -1203,10 +1200,10 @@ def social_associate_user_helper(backend: BaseAuth, return_data: Dict[str, Any], | ||||
|     if full_name: | ||||
|         return_data["full_name"] = full_name | ||||
|     else: | ||||
|         # In SAML authentication, the IdP may support only sending | ||||
|         # the first and last name as separate attributes - in that case | ||||
|         # Some authentications methods like Apple and SAML send | ||||
|         # first name and last name as seperate attributes. In that case | ||||
|         # we construct the full name from them. | ||||
|         return_data["full_name"] = f"{first_name} {last_name}".strip()  # strip removes the unnecessary ' ' | ||||
|         return_data["full_name"] = f"{first_name or ''} {last_name or ''}".strip()  # strip removes the unnecessary ' ' | ||||
|  | ||||
|     return user_profile | ||||
|  | ||||
| @@ -1621,37 +1618,6 @@ class AppleAuthBackend(SocialAuthMixin, AppleIdAuth): | ||||
|                 self.strategy.session_set(param, value) | ||||
|         return request_state | ||||
|  | ||||
|     def decode_id_token(self, id_token: str) -> Dict[str, Any]: | ||||
|         '''Decode and validate JWT token from Apple and return payload including user data. | ||||
|  | ||||
|         We override this method from upstream python-social-auth, for two reasons: | ||||
|         * To improve error handling (correctly raising AuthFailed; see comment below). | ||||
|         * To facilitate this to support the native flow, where | ||||
|           the Apple-generated id_token is signed for "Bundle ID" | ||||
|           audience instead of "Services ID". | ||||
|  | ||||
|         It is likely that small upstream tweaks could make it possible | ||||
|         to make this function a thin wrapper around the upstream | ||||
|         method; we may want to submit a PR to achieve that. | ||||
|         ''' | ||||
|         if self.is_native_flow(): | ||||
|             audience = self.setting("BUNDLE_ID") | ||||
|         else: | ||||
|             audience = self.setting("SERVICES_ID") | ||||
|  | ||||
|         try: | ||||
|             kid = jwt.get_unverified_header(id_token).get('kid') | ||||
|             public_key = RSAAlgorithm.from_jwk(self.get_apple_jwk(kid)) | ||||
|             decoded = jwt.decode(id_token, key=public_key, | ||||
|                                  audience=audience, algorithm="RS256") | ||||
|         except PyJWTError: | ||||
|             # Changed from upstream python-social-auth to raise | ||||
|             # AuthFailed, which is more appropriate than upstream's | ||||
|             # AuthCanceled, for this case. | ||||
|             raise AuthFailed(self, "Token validation failed") | ||||
|  | ||||
|         return decoded | ||||
|  | ||||
|     def auth_complete(self, *args: Any, **kwargs: Any) -> Optional[HttpResponse]: | ||||
|         if not self.is_native_flow(): | ||||
|             # The default implementation in python-social-auth is the browser flow. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user