this the the whole backend code
i have created my app in cerner code console
whose client-id is aff355a8-6107-46ef-83ea-57b01502a944
i am using Product Family
Millennium
Products
Ignite APIs for Millennium: FHIR DSTU 2, All
i have also created account on CernerCentral
System Accounts
also i have created and linked my json key this is how it looks

import requests , json
import jwt
import datetime
import uuid
import base64
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives.serialization import load_pem_private_key
from cryptography.hazmat.primitives import serialization
class DateTimeEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime):
return obj.isoformat()
return super().default(obj)
pem_file_path ="C:\\test\\newprivatekey.pem"
with open(pem_file_path, "rb") as key_file:
private_key = serialization.load_pem_private_key(
key_file.read(),
password=None # Optional: Password for encrypted private key
)
jti = str(uuid.uuid4())
# define JWT headers
header={
"kty" : "RSA",
"e" : "AQAB",
"kid" : "001",
"alg" : "RS384"
}
header_string = json.dumps(header)
# Define the JWT payload
payload = {
"iss": "aff355a8-6107-46ef-83ea-57b01502a944",
"sub": "aff355a8-6107-46ef-83ea-57b01502a944",
"aud": "https://authorization.cerner.com/tenants/ec2458f2-1e24-41c8-b71b-0e701af7583d/protocols/oauth2/profiles/smart-v1/token",
"jti": jti,
'exp':'2023-06-22 09:28:45.175603',
# "exp": datetime.datetime.utcnow() + datetime.timedelta(minutes=5),
#"state": "a4c16a46-2c46-482c-8d66-4cc4a2990bda",
#"launch":"a17aba51-1395-48d3-b3a9-73f2baf784da"
}
print(datetime.datetime.utcnow() + datetime.timedelta(minutes=5))
payload_string = json.dumps(payload)
header_b64 = base64.urlsafe_b64encode(header_string.encode("utf-8")).rstrip(b"=")
payload_b64 = base64.urlsafe_b64encode(payload_string.encode("utf-8")).rstrip(b"=")
data = header_b64 + b"." + payload_b64
signature = private_key.sign(data, padding.PKCS1v15(), hashes.SHA384())
signature_b64 = base64.urlsafe_b64encode(signature).rstrip(b"=")
jwt_string = header_b64.decode("utf-8") + "." + payload_b64.decode("utf-8") + "." + signature_b64.decode("utf-8")
print(jwt_string)
# Use the jwt_string for authentication with FHIR Epic
# POST requests
url = "https://authorization.cerner.com/tenants/ec2458f2-1e24-41c8-b71b-0e701af7583d/protocols/oauth2/profiles/smart-v1/token"
headers = {"Content-Type": "application/x-www-form-urlencoded"}
payload = {
"Scope": "system/Patient.read",
"grant_type": "client_credentials",
"client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
"client_assertion": jwt_string
}
response = requests.post(url, headers=headers, data=payload)
print("Response status code:", response.status_code)
print("Response body:", response.json())
ERROR
2023-06-23 13:57:40.164594
eyJrdHkiOiAiUlNBIiwgImUiOiAiQVFBQiIsICJraWQiOiAiMDAxIiwgImFsZyI6ICJSUzM4NCJ9.eyJpc3MiOiAiYWZmMzU1YTgtNjEwNy00NmVmLTgzZWEtNTdiMDE1MDJhOTQ0IiwgInN1YiI6ICJhZmYzNTVhOC02MTA3LTQ2ZWYtODNlYS01N2IwMTUwMmE5NDQiLCAiYXVkIjogImh0dHBzOi8vYXV0aG9yaXphdGlvbi5jZXJuZXIuY29tL3RlbmFudHMvZWMyNDU4ZjItMWUyNC00MWM4LWI3MWItMGU3MDFhZjc1ODNkL3Byb3RvY29scy9vYXV0aDIvcHJvZmlsZXMvc21hcnQtdjEvdG9rZW4iLCAianRpIjogIjc5NGZmMDljLWE2ZmUtNGI5OC1iM2Y0LWM1Y2E2NWRmZjRmZCIsICJleHAiOiAiMjAyMy0wNi0yMiAwOToyODo0NS4xNzU2MDMifQ.WYtAKaVM6Kn1RzC8i-P780qqGoJbAkCD1jC5mylrp5ByJp3SVsc2LJ-KUFT7FEDrp7hmEIqUx3vK2PdHCJee1eburjAmb_zndmpjzsDSnbxha_XUkq8v5vq7vLw15XdAxk0gafJUJFLEvk0MlwpNRyjod8GHeMCzjycxgZIhzYSBrvYbMm7gef7f-_innx4U8XGKLXKEFc2xrpINeS3JaGnq5eFyWdow4jHoP0G7slDd4ldhvdjWvEEJEduY6IyY6nJG1WvHv1E9_7LIcmX3cCEUcX6wS1JCvBEuFGZOc8BJn8DnJiwkE-Nzzkrzqk7bOdGebvId3A85xykBvKN_2g
Response status code: 200
Traceback (most recent call last):
File "C:\Users\Kartikey\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\requests\models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\Kartikey\Downloads\import requests.py", line 73, in <module>
print("Response body:", response.json())
^^^^^^^^^^^^^^^
File "C:\Users\Kartikey\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 2 (char 1)
PLEASE HELP OUT