From 01f0f8d456221ecd944e80933c64ef3009d532bc Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Tue, 9 May 2023 15:19:42 +0200 Subject: [PATCH] mgr/dashboard: SSO error: AttributeError: 'str' object has no attribute 'decode' The token is `str` in PyJWT >= 2 and Python3. Check `controllers/auth.py` where the same code is used. Fixes: https://tracker.ceph.com/issues/59689 References: https://github.com/SUSE/ceph/pull/506 Signed-off-by: Volker Theile (cherry picked from commit 0fc6e7637657a96acfb0aa01dde6b3fbd81a136d) --- src/pybind/mgr/dashboard/controllers/saml2.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/dashboard/controllers/saml2.py b/src/pybind/mgr/dashboard/controllers/saml2.py index 6de8cf0df73d1..76b8e8498aa97 100644 --- a/src/pybind/mgr/dashboard/controllers/saml2.py +++ b/src/pybind/mgr/dashboard/controllers/saml2.py @@ -70,7 +70,10 @@ class Saml2(BaseController, ControllerAuthMixin): token = JwtManager.gen_token(username) JwtManager.set_user(JwtManager.decode_token(token)) - token = token.decode('utf-8') + + # For backward-compatibility: PyJWT versions < 2.0.0 return bytes. + token = token.decode('utf-8') if isinstance(token, bytes) else token + self._set_token_cookie(url_prefix, token) raise cherrypy.HTTPRedirect("{}/#/login?access_token={}".format(url_prefix, token)) -- 2.39.5