Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 40f14bb

Browse files
Switch token separate to URL safe character . (dot)
Some email clients replace double slashes with a single slash. The double slash occured for users with no last_login date (newly created users). To bypass this issue, the separator is changed to . (dot) as it is a non-reserved URL safe caracter (RFC3986 2.3) and not port of the base64url alphabet. See also: https://www.ietf.org/rfc/rfc3986.txt https://tools.ietf.org/html/rfc4648
1 parent 68ba00f commit 40f14bb

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

‎mailauth/backends.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
class MailAuthBackend(ModelBackend):
15-
signer = signing.UserSigner(sep='/')
15+
signer = signing.UserSigner()
1616

1717
def authenticate(self, request, token=None):
1818
max_age = getattr(settings, 'LOGIN_URL_TIMEOUT', 60 * 15)

‎mailauth/signing.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class UserDoesNotExist(signing.BadSignature):
1414
class UserSigner(signing.TimestampSigner):
1515
"""Issue and verify URL safe access tokens for users."""
1616

17+
def __init__(self, key=None, sep='.', salt=None):
18+
super().__init__(key=key, sep=sep, salt=salt)
19+
1720
@staticmethod
1821
def to_timestamp(value):
1922
"""

‎tests/conftest.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def admin_user(db):
3636
@pytest.fixture()
3737
def signature():
3838
"""Return a signature matching the user fixture."""
39-
return 'LZ/173QUS/1Hjptg/fTLJcaon_7zMDyFTIFtlDqbdSt4'
39+
return 'LZ.173QUS.1Hjptg.lf2hFgOXQtjQsFypS2ItRG2hkpA'
4040

4141

4242
@pytest.fixture()
4343
def signer():
4444
"""Return a forzen version of the UserSigner."""
45-
return FrozenUserSigner(sep='/')
45+
return FrozenUserSigner()

‎tests/test_backends.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ def test_get_login_url(self, signer, signature):
6262
backend = MailAuthBackend()
6363
MailAuthBackend.signer = signer
6464
assert backend.get_login_url(signature) == (
65-
"/accounts/login/LZ/173QUS/1Hjptg/fTLJcaon_7zMDyFTIFtlDqbdSt4"
65+
"/accounts/login/LZ.173QUS.1Hjptg.lf2hFgOXQtjQsFypS2ItRG2hkpA"
6666
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /