mirror of https://github.com/zulip/zulip.git
auth: Make apple log in and sign up buttons consistent with others.
This commit is contained in:
parent
f8ea5f3769
commit
0445311430
|
@ -699,29 +699,6 @@ button.login-social-button {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Apple is very particular about the appearance of its authentication
|
|
||||||
buttons, which means we cannot use our generic label+icon system for
|
|
||||||
their authentication backend while complying with their policies.
|
|
||||||
|
|
||||||
So here we use the buttons provided by Apple, which include the sign
|
|
||||||
in text (Sign in with Apple/Continue with Apple). To make these
|
|
||||||
consistent with other buttons, we request buttons of size 328x50 and
|
|
||||||
the following styling sets the appropriate width and height to make it
|
|
||||||
fit with other other social authentication buttons. We also set the
|
|
||||||
font size to zero to hide the text our own code in the
|
|
||||||
login/registration pages would generate, to avoid extra conditionals
|
|
||||||
in the HTML templates.
|
|
||||||
*/
|
|
||||||
button#login_auth_button_apple,
|
|
||||||
button#register_auth_button_apple {
|
|
||||||
width: 328px;
|
|
||||||
height: 50px;
|
|
||||||
background-size: auto 100%;
|
|
||||||
background-position: 0px 100%;
|
|
||||||
font-size: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#find-account-section {
|
#find-account-section {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
|
|
|
@ -78,8 +78,7 @@ page can be easily identified in it's respective JavaScript file -->
|
||||||
<form class="form-inline" action="{{ backend.signup_url }}" method="get">
|
<form class="form-inline" action="{{ backend.signup_url }}" method="get">
|
||||||
<input type='hidden' name='multiuse_object_key' value='{{ multiuse_object_key }}' />
|
<input type='hidden' name='multiuse_object_key' value='{{ multiuse_object_key }}' />
|
||||||
<button id="register_{{ backend.button_id_suffix }}" class="login-social-button full-width"
|
<button id="register_{{ backend.button_id_suffix }}" class="login-social-button full-width"
|
||||||
{% if backend.display_name == "Apple" %} style="background-image:url(https://appleid.cdn-apple.com/appleid/button/?width=328&height=50&color=white&locale={{ apple_locale }}&type=continue)"
|
{% if backend.display_icon %} style="background-image:url({{ backend.display_icon }})" {% endif %}>
|
||||||
{% elif backend.display_icon %} style="background-image:url({{ backend.display_icon }})" {% endif %}>
|
|
||||||
{{ _('Sign up with %(identity_provider)s', identity_provider=backend.display_name) }}
|
{{ _('Sign up with %(identity_provider)s', identity_provider=backend.display_name) }}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -114,9 +114,7 @@ page can be easily identified in it's respective JavaScript file. -->
|
||||||
<form class="social_login_form form-inline" action="{{ backend.login_url }}" method="get">
|
<form class="social_login_form form-inline" action="{{ backend.login_url }}" method="get">
|
||||||
<input type="hidden" name="next" value="{{ next }}">
|
<input type="hidden" name="next" value="{{ next }}">
|
||||||
<button id="login_{{ backend.button_id_suffix }}" class="login-social-button"
|
<button id="login_{{ backend.button_id_suffix }}" class="login-social-button"
|
||||||
{% if backend.display_name == "Apple" %} style="background-image: url(https://appleid.cdn-apple.com/appleid/button/?width=328&height=50&color=white&locale={{ apple_locale }});"
|
{% if backend.display_icon %} style="background-image:url({{ backend.display_icon }})" {% endif %}> {{ _('Log in with %(identity_provider)s', identity_provider=backend.display_name) }}
|
||||||
{% elif backend.display_icon %} style="background-image:url({{ backend.display_icon }})" {% endif %}>
|
|
||||||
{{ _('Log in with %(identity_provider)s', identity_provider=backend.display_name) }}
|
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -499,8 +499,6 @@ html_rules: List["Rule"] = whitespace_rules + prose_style_rules + [
|
||||||
'good_lines': ['<input class="stream-list-filter" type="text" placeholder="{{ _(\'Search streams\') }}" />'],
|
'good_lines': ['<input class="stream-list-filter" type="text" placeholder="{{ _(\'Search streams\') }}" />'],
|
||||||
'bad_lines': ['<input placeholder="foo">']},
|
'bad_lines': ['<input placeholder="foo">']},
|
||||||
{'pattern': '={',
|
{'pattern': '={',
|
||||||
# TODO: Improve the Apple auth patterns so we can remove this.
|
|
||||||
'exclude_pattern': 'appleid.cdn-apple.com/appleid/button',
|
|
||||||
'description': "Likely missing quoting in HTML attribute",
|
'description': "Likely missing quoting in HTML attribute",
|
||||||
'good_lines': ['<a href="{{variable}}">'],
|
'good_lines': ['<a href="{{variable}}">'],
|
||||||
'bad_lines': ['<a href={{variable}}>']},
|
'bad_lines': ['<a href={{variable}}>']},
|
||||||
|
|
|
@ -18,7 +18,6 @@ from zerver.lib.subdomains import get_subdomain
|
||||||
from zerver.models import Realm, UserProfile, get_realm
|
from zerver.models import Realm, UserProfile, get_realm
|
||||||
from zproject.backends import (
|
from zproject.backends import (
|
||||||
AUTH_BACKEND_NAME_MAP,
|
AUTH_BACKEND_NAME_MAP,
|
||||||
AppleAuthBackend,
|
|
||||||
any_social_backend_enabled,
|
any_social_backend_enabled,
|
||||||
auth_enabled_helper,
|
auth_enabled_helper,
|
||||||
get_external_method_dicts,
|
get_external_method_dicts,
|
||||||
|
@ -168,7 +167,6 @@ def login_context(request: HttpRequest) -> Dict[str, Any]:
|
||||||
'password_auth_enabled': password_auth_enabled(realm),
|
'password_auth_enabled': password_auth_enabled(realm),
|
||||||
'any_social_backend_enabled': any_social_backend_enabled(realm),
|
'any_social_backend_enabled': any_social_backend_enabled(realm),
|
||||||
'two_factor_authentication_enabled': settings.TWO_FACTOR_AUTHENTICATION_ENABLED,
|
'two_factor_authentication_enabled': settings.TWO_FACTOR_AUTHENTICATION_ENABLED,
|
||||||
'apple_locale': AppleAuthBackend.get_apple_locale(request.LANGUAGE_CODE),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if realm is not None and realm.description:
|
if realm is not None and realm.description:
|
||||||
|
|
|
@ -2017,25 +2017,6 @@ class AppleIdAuthBackendTest(AppleAuthMixin, SocialAuthBase):
|
||||||
with self.settings(AUTHENTICATION_BACKENDS=('zproject.backends.AppleAuthBackend',)):
|
with self.settings(AUTHENTICATION_BACKENDS=('zproject.backends.AppleAuthBackend',)):
|
||||||
self.assertTrue(apple_auth_enabled())
|
self.assertTrue(apple_auth_enabled())
|
||||||
|
|
||||||
def test_get_apple_locale(self) -> None:
|
|
||||||
language_locale = [('ar', 'ar_SA'), ('ca', 'ca_ES'), ('cs', 'cs_CZ'),
|
|
||||||
('da', 'da_DK'), ('de', 'de_DE'), ('el', 'el_GR'),
|
|
||||||
('en', 'en_US'), ('es', 'es_ES'), ('fi', 'fi_FI'),
|
|
||||||
('fr', 'fr_FR'), ('hr', 'hr_HR'), ('hu', 'hu_HU'),
|
|
||||||
('id', 'id_ID'), ('it', 'it_IT'), ('iw', 'iw_IL'),
|
|
||||||
('ja', 'ja_JP'), ('ko', 'ko_KR'), ('ms', 'ms_MY'),
|
|
||||||
('nl', 'nl_NL'), ('no', 'no_NO'), ('pl', 'pl_PL'),
|
|
||||||
('pt', 'pt_PT'), ('ro', 'ro_RO'), ('ru', 'ru_RU'),
|
|
||||||
('sk', 'sk_SK'), ('sv', 'sv_SE'), ('th', 'th_TH'),
|
|
||||||
('tr', 'tr_TR'), ('uk', 'uk_UA'), ('vi', 'vi_VI'),
|
|
||||||
('zh', 'zh_CN')]
|
|
||||||
|
|
||||||
for language_code, locale in language_locale:
|
|
||||||
self.assertEqual(AppleAuthBackend.get_apple_locale(language_code), locale)
|
|
||||||
|
|
||||||
# return 'en_US' if invalid `language_code` is given.
|
|
||||||
self.assertEqual(AppleAuthBackend.get_apple_locale(':)'), 'en_US')
|
|
||||||
|
|
||||||
def test_auth_registration_with_no_name_sent_from_apple(self) -> None:
|
def test_auth_registration_with_no_name_sent_from_apple(self) -> None:
|
||||||
"""
|
"""
|
||||||
Apple doesn't send the name in consecutive attempts if user registration
|
Apple doesn't send the name in consecutive attempts if user registration
|
||||||
|
|
|
@ -1548,6 +1548,7 @@ class AppleAuthBackend(SocialAuthMixin, AppleIdAuth):
|
||||||
sort_order = 10
|
sort_order = 10
|
||||||
name = "apple"
|
name = "apple"
|
||||||
auth_backend_name = "Apple"
|
auth_backend_name = "Apple"
|
||||||
|
display_icon = "/static/images/landing-page/logos/apple-icon.png"
|
||||||
|
|
||||||
# Apple only sends `name` in its response the first time a user
|
# Apple only sends `name` in its response the first time a user
|
||||||
# tries to sign up, so we won't have it in consecutive attempts.
|
# tries to sign up, so we won't have it in consecutive attempts.
|
||||||
|
@ -1556,28 +1557,6 @@ class AppleAuthBackend(SocialAuthMixin, AppleIdAuth):
|
||||||
full_name_validated = True
|
full_name_validated = True
|
||||||
REDIS_EXPIRATION_SECONDS = 60*10
|
REDIS_EXPIRATION_SECONDS = 60*10
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_apple_locale(django_language_code: str) -> str:
|
|
||||||
'''
|
|
||||||
Get the suitable apple supported locale with language code
|
|
||||||
for the Sign in / Continue with Apple buttons it provides.
|
|
||||||
'''
|
|
||||||
# The following is a list of locale values supported by Apple to send
|
|
||||||
# as params to URL which renders "Sign in with Apple" and "Continue with Apple"
|
|
||||||
# buttons. Gathered from
|
|
||||||
# https://developer.apple.com/documentation/signinwithapplejs/incorporating_sign_in_with_apple_into_other_platforms .
|
|
||||||
supported_locales = ['ar_SA', 'ca_ES', 'cs_CZ', 'da_DK', 'de_DE',
|
|
||||||
'el_GR', 'en_US', 'es_ES', 'fi_FI', 'fr_FR',
|
|
||||||
'hr_HR', 'hu_HU', 'id_ID', 'it_IT', 'iw_IL',
|
|
||||||
'ja_JP', 'ko_KR', 'ms_MY', 'nl_NL', 'no_NO',
|
|
||||||
'pl_PL', 'pt_PT', 'ro_RO', 'ru_RU', 'sk_SK',
|
|
||||||
'sv_SE', 'th_TH', 'tr_TR', 'uk_UA', 'vi_VI',
|
|
||||||
'zh_CN']
|
|
||||||
for locale in supported_locales:
|
|
||||||
if django_language_code in locale:
|
|
||||||
return locale
|
|
||||||
return 'en_US'
|
|
||||||
|
|
||||||
def is_native_flow(self) -> bool:
|
def is_native_flow(self) -> bool:
|
||||||
return self.strategy.request_data().get('native_flow', False)
|
return self.strategy.request_data().get('native_flow', False)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue