Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

add org.matrix.login.jwt so that m.login.jwt can be deprecated #7675

Merged
merged 8 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7675.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Rename m.login.jwt to org.matrix.login.jwt as that is not in the spec.
5 changes: 4 additions & 1 deletion synapse/rest/client/v1/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class LoginRestServlet(RestServlet):
CAS_TYPE = "m.login.cas"
SSO_TYPE = "m.login.sso"
TOKEN_TYPE = "m.login.token"
JWT_TYPE = "m.login.jwt"
JWT_TYPE = "org.matrix.login.jwt"
JWT_TYPE_DEPRECATED = "m.login.jwt"

def __init__(self, hs):
super(LoginRestServlet, self).__init__()
Expand Down Expand Up @@ -108,6 +109,7 @@ def on_GET(self, request):
flows = []
if self.jwt_enabled:
flows.append({"type": LoginRestServlet.JWT_TYPE})
flows.append({"type": LoginRestServlet.JWT_TYPE_DEPRECATED})

if self.cas_enabled:
# we advertise CAS for backwards compat, though MSC1721 renamed it
Expand Down Expand Up @@ -141,6 +143,7 @@ async def on_POST(self, request):
try:
if self.jwt_enabled and (
login_submission["type"] == LoginRestServlet.JWT_TYPE
or login_submission["type"] == LoginRestServlet.JWT_TYPE_DEPRECATED
):
result = await self.do_jwt_login(login_submission)
elif login_submission["type"] == LoginRestServlet.TOKEN_TYPE:
Expand Down
10 changes: 7 additions & 3 deletions tests/rest/client/v1/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,9 @@ def jwt_encode(self, token, secret=jwt_secret):
return jwt.encode(token, secret, "HS256").decode("ascii")

def jwt_login(self, *args):
params = json.dumps({"type": "m.login.jwt", "token": self.jwt_encode(*args)})
params = json.dumps(
{"type": "org.matrix.login.jwt", "token": self.jwt_encode(*args)}
)
request, channel = self.make_request(b"POST", LOGIN_URL, params)
self.render(request)
return channel
Expand Down Expand Up @@ -568,7 +570,7 @@ def test_login_no_sub(self):
self.assertEqual(channel.json_body["error"], "Invalid JWT")

def test_login_no_token(self):
params = json.dumps({"type": "m.login.jwt"})
params = json.dumps({"type": "org.matrix.login.jwt"})
request, channel = self.make_request(b"POST", LOGIN_URL, params)
self.render(request)
self.assertEqual(channel.result["code"], b"401", channel.result)
Expand Down Expand Up @@ -640,7 +642,9 @@ def jwt_encode(self, token, secret=jwt_privatekey):
return jwt.encode(token, secret, "RS256").decode("ascii")

def jwt_login(self, *args):
params = json.dumps({"type": "m.login.jwt", "token": self.jwt_encode(*args)})
params = json.dumps(
{"type": "org.matrix.login.jwt", "token": self.jwt_encode(*args)}
)
request, channel = self.make_request(b"POST", LOGIN_URL, params)
self.render(request)
return channel
Expand Down