Unable to register API client. Getting error - "Unexpected end of JSON input"

Hi, I am new to Openemr. I have installed Openemr version 6.0.1 on top of xampp in Windows. I am unable to register new API client in OpenEMR. I am getting an error message - “Unexpected end of JSON input”.

This is the details of the request I am making:
Request URL: https://localhost/openemr/oauth2/default/registration
Request Method: POST
Content-Type: application/json
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36
Request Payload:
{application_type: “private”,…}

** application_type: “private”**
** client_name: “Test_App”**
** contacts: [“chiranth.kumar@ltts.com”]**
** initiate_login_uri: “https:// <openemr_url>/openemr/swagger/index.html”**
** jwks: “”**
** jwks_uri: “”**
** post_logout_redirect_uris: [""]**
** 0: “”**

** redirect_uris: [“https://<openemr_url>/openemr/swagger/oauth2-redirect.html”]**
** 0: “https://<openemr_url>/openemr/swagger/oauth2-redirect.html”**

** scope: “openid fhirUser online_access offline_access launch launch/patient api:oemr api:fhir api:port profile name address given_name family_name nickname phone phone_verified email email_verified site:default patient/AllergyIntolerance.read patient/CarePlan.read patient/CareTeam.read patient/Condition.read patient/Device.read patient/DiagnosticReport.read patient/DocumentReference.read patient/Encounter.read patient/Goal.read patient/Immunization.read patient/Location.read patient/Medication.read patient/MedicationRequest.read patient/Observation.read patient/Organization.read patient/Patient.read patient/Person.read patient/Practitioner.read patient/Procedure.read patient/Provenance.read user/AllergyIntolerance.read user/CarePlan.read user/CareTeam.read user/Condition.read user/Coverage.read user/Device.read user/DiagnosticReport.read user/DocumentReference.read user/Encounter.read user/Goal.read user/Immunization.read user/Location.read user/Medication.read user/MedicationRequest.read user/Observation.read user/Organization.read user/Organization.write user/Patient.read user/Patient.write user/Person.read user/Practitioner.read user/Practitioner.write user/PractitionerRole.read user/Procedure.read user/Provenance.read”**
** token_endpoint_auth_method: “client_secret_post”**.

There is no response received and got 500 (Internal Server Error), SyntaxError: Unexpected end of JSON input at register-app.php:89:39

Can you please help in resolving this issue.

Forgot to mention that I am trying to register new API client in “https://localhost/openemr/interface/smart/register-app.php

Check your FHIR server url in the Globals → Connectors → FHIR Server Address. Make sure it is set to https://localhost/openemr

1 Like

Hi Stephen, thanks for the input. I changed FHIR server url in the Globals → Connectors → FHIR Server Address value to https://localhost/openemr. Earlier it was only till “localhost” and “/openemr” was not present.

Now I am getting the following error:
SyntaxError: Unexpected token < in JSON at position 0
Fetch failed loading: POST “https://localhost/openemr/openemr/oauth2/default/registration

openemr has repeated twice (/openemr/openemr) in the request URL as you can see above. That is why we are receiving this error.


If I change Globals → Connectors → FHIR Server Address value to back to https://localhost I get the same error as I mentioned in my first post above. Except this time it is pointing that the issue is at line # 81 in the script register-app.php.

Attached is the screenshot of the error for your reference. I am not a PHP developer.

Can you please suggest?

What do you see in your apache error logs? If you go to the network console and actually look at the 500 error response that you get back does it list a stack trace or any error information?

1 Like

Thanks Stephen for pointing that out. In the apache error logs it was mentioned as below:
“[Fri Jun 10 05:55:45.003419 2022] [php:error] [pid 36376:tid 1872] [client ::1:55696] PHP Parse error: syntax error, unexpected double-quoted string “default_md”, expecting “]” in C:\xampp\htdocs\openemr\src\Common\Auth\OAuth2KeyConfig.php on line 118, referer: https://localhost/openemr/interface/smart/register-app.php”.

I realized that I had missed a comma in the script OAuth2KeyConfig.php at line 117 as shown in the below code (Second line):
$keysConfig = [
"config" => "C:\xampp\php\extras\openssl\openssl.cnf"
"default_md" => “sha256”,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
"private_key_bits" => 2048,
"encrypt_key" => true,
"encrypt_key_cipher" => OPENSSL_CIPHER_AES_256_CBC

I corrected this by adding a comma there.

Now I am getting a different error while registering the API client as shown below:

{error: ‘server_error’, error_description: ‘The authorization server encountered an unexpected…y error - problem with authorization server keys.’, message: ‘The authorization server encountered an unexpected…y error - problem with authorization server keys.’}

Fetch failed loading: POST "https://localhost/openemr/oauth2/default/registration"

In the Apache error log shows as below:

[Fri Jun 10 06:04:09.709577 2022] [php:notice] [pid 36376:tid 1872] [client ::1:56370] [2022-06-10T02:34:09.715467+02:00] OpenEMR.ERROR: OpenEMR error - key generation broken during oauth2, so forced exit [] [], referer: https://localhost/openemr/interface/smart/register-app.php

There is some issue with the authorization key generation. Can you please help.

In the network console, the 500 Error response is showing as below:

{“error”:“server_error”,“error_description”:“The authorization server encountered an unexpected condition which prevented it from fulfilling the request: Security error - problem with authorization server keys.”,“message”:“The authorization server encountered an unexpected condition which prevented it from fulfilling the request: Security error - problem with authorization server keys.”}

Why are you messing with the Oauth2KeyConfig? Was your openssl not working on windows? As you can see from the error logs, whatever setup you are using for openssl is not working on windows.

I recommend writing a simple php script that you can access from your XAMP installation to isolate your problem. This will remove all the extra OpenEMR bits out so you can figure out why openssl is breaking for you. Then you can identify if you actually need to pass in a config value. You shouldn’t have to as we have OpenEMR users on windows running fine. If you do require the line than we need to figure out why.

Your php script would be as sample as doing the following:

$keysConfig = [
                "default_md" => "sha256",
                "private_key_type" => OPENSSL_KEYTYPE_RSA,
                "private_key_bits" => 2048,
                "encrypt_key" => true,
                "encrypt_key_cipher" => OPENSSL_CIPHER_AES_256_CBC
$keys = \openssl_pkey_new($keysConfig);
if ($keys === false) {
die("OpenSSL is not working!");
echo "OpenSSL is working!"

Hi Stephen, thank you so much. I wrote the php script you gave and saved it in the file “testSSL.php” under “C:\xampp\htdocs\test” directory. I ran the script by entering the url - “https://localhost/test/testSSL.php” in the browser. I am getting the following output -OpenSSL is not working!

How do I get the OpenSSL working?

For your information, I enclosed the script you gave within the html tags and ran it as shown in the attached snippet.


Request you to kindly help.

Sorry Chiranth, I’m in the middle of our ONC implementation so I can’t dig deeper on why your OpenSSL is not working for you. I’m also not a windows developer. I suggest searching google for answers on how to configure openssl or hire an IT consultant to assist you. Perhaps someone else on the forum can help you configure OpenSSL.

1 Like

Hi Stephen, no problem. Thanks for all the help.

I was able to fix and configure OpenSSL now. I had not set the OPENSSL_CONF system variable under environment variables properly earlier. I fixed it. Now OpenSSL is working fine (output of the above PHP script you have given is says “OpenSSL is working!” ) and I am able to register new API client. But when I try to authorize the client and get the access token, I am getting error “404 Not Found”. Following is the response I am getting:


404 Not Found

Not Found

The requested URL was not found on this server.

Apache/2.4.52 (Win64) OpenSSL/1.1.1m PHP/8.1.4 Server at localhost Port 80 "

I am not sure what I am missing here. Any pointers or suggestions regarding this would be of great help.


are you running 6.0.1 or 6.1.0?

I am running OpenEMR version 6.1.0.

ok, can you try to reproduce the issue on one of the demos?

I am unable to reproduce this issue on the demos. It is working fine in Demos. But it is not working in my local OpenEMR setup. It looks like I am missing something here with Oauth2.0 setup or some other issue may be. I am not sure what I am missing. Can you please help.

I have openssl configured, when I hit url: https://localhost/openemr/interface/smart/register-app.php and fill the form and submit, I get an error of:
JSON.parse: unexpected character at line 1 column 1 of the JSON data