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”,…}
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.
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.
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?
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 ];
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.’}
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:
<?php
$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!
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.
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.
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.