From: Volker Theile Date: Tue, 9 May 2023 13:19:42 +0000 (+0200) Subject: mgr/dashboard: SSO error: AttributeError: 'str' object has no attribute 'decode' X-Git-Tag: v18.1.1~3^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=309be0fee26c6abdfc7533bf908f0c6270f049a4;p=ceph.git 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) --- diff --git a/src/pybind/mgr/dashboard/controllers/saml2.py b/src/pybind/mgr/dashboard/controllers/saml2.py index 55445bc94d7b2..c11b18a27bc7e 100644 --- a/src/pybind/mgr/dashboard/controllers/saml2.py +++ b/src/pybind/mgr/dashboard/controllers/saml2.py @@ -69,7 +69,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))