From 71d7d75a1ac218ce9e0ab5c0a76e5ab605b2af44 Mon Sep 17 00:00:00 2001 From: Maxim Babushkin Date: Thu, 29 Feb 2024 15:28:42 +0200 Subject: [PATCH 1/2] [auth] - Fix token decode failure While decoding, the "decode_token" function fails with the following message: "The error was: jwt.exceptions.DecodeError: It is required that you pass in a value for the "algorithms" argument when calling decode()" Adding the "'verify_signature': False" option to override the failure. --- ibmcloud_python_sdk/auth.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ibmcloud_python_sdk/auth.py b/ibmcloud_python_sdk/auth.py index 5b3072c8b..fb37e01de 100644 --- a/ibmcloud_python_sdk/auth.py +++ b/ibmcloud_python_sdk/auth.py @@ -15,7 +15,8 @@ def decode_token(): """ try: token = get_headers()["Authorization"] - return decode(token.split(" ")[1], verify=False) + return decode(token.split(" ")[1], verify=False, + options={'verify_signature': False}) except Exception as error: print("Error decoding token. {}".format(error)) From fe5f9ce044d77b6d9de468cea71ca57571688dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Sat, 2 Mar 2024 09:01:40 -0500 Subject: [PATCH 2/2] [auth] Sepcify RS256 algo with unverified signature --- ibmcloud_python_sdk/auth.py | 7 +++++-- requirements.txt | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ibmcloud_python_sdk/auth.py b/ibmcloud_python_sdk/auth.py index fb37e01de..8ac48a0f3 100644 --- a/ibmcloud_python_sdk/auth.py +++ b/ibmcloud_python_sdk/auth.py @@ -15,8 +15,11 @@ def decode_token(): """ try: token = get_headers()["Authorization"] - return decode(token.split(" ")[1], verify=False, - options={'verify_signature': False}) + return decode( + token.split(" ")[1], + algorithms=["RS256"], + options={"verify_signature": False}, + ) except Exception as error: print("Error decoding token. {}".format(error)) diff --git a/requirements.txt b/requirements.txt index 1baace060..07b235a49 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ PyYAML>=3.12 softlayer==5.8.7 -PyJWT==2.4.0 +PyJWT==2.8.0 ibm-cos-sdk==2.6.2 botocore>=1.16.9 pymemcache==3.2.0 +cryptography==42.0.5