Swagger request getting 401 response after registration

I have the same issue.

registration is done via postman as in the picture.
authentication is done via swagger as seen in the screenshot.
Get api/patient did not work as seen in the screenshot because the server denied! But the authentication step worked just fine!

Look at the scope parameter in your registration request. Your client is not requesting any access to the user/patient.read scope, I’ve moved your post to a different issue as your not getting invalid client but a 401 access denied response. If you turn on under Config in Logging the System Error Logging Options to Debug mode and you’ll get more details in your php error log of what you are doing wrong.

1 Like

Thank you.

Could you please let me know which one of the get or post items on swagger should work with this scope?

In addition, I have tried the full scope, but that gave another error which I will post here in an hour.

I did turn on the logging, If you could tell me where to find the log files I would appreciate it a lot. Thanks.

I found this in the log files inside oauth2 folder

OpenEMR.ERROR: OpenEMR\Common\Auth\OpenIDConnect\Grant\CustomAuthCodeGrant->validateClient() client returned was not enabled

OpenEMR.ERROR: OpenEMR\Common\Auth\OpenIDConnect\Grant\CustomAuthCodeGrant->validateRedirectUri() Invalid client detected. Failed to validate redirect uri {“redirectUri”:“https://emr-easy.com/swagger/oauth2-redirect.html",“client”:“h2mw7UT_a1lRPVSrR0JK2RQIgzfRxLdgXv9zGXy7p2I”,“message”:"Client authentication failed”,“trace”:“#0 /home/ddfvd6qhit7y/public_html/vendor/league/oauth2-server/src/Grant/AbstractGrant.php(290): League\OAuth2\Server\Exception\OAuthServerException::invalidClient()\n#1 /home/ddfvd6qhit7y/public_html/src/Common/Auth/OpenIDConnect/Grant/CustomAuthCodeGrant.php(101): League\OAuth2\Server\Grant\AbstractGrant->validateRedirectUri()\n#2 /home/ddfvd6qhit7y/public_html/vendor/league/oauth2-server/src/Grant/AuthCodeGrant.php(281): OpenEMR\Common\Auth\OpenIDConnect\Grant\CustomAuthCodeGrant->validateRedirectUri()\n#3 /home/ddfvd6qhit7y/public_html/src/Common/Auth/OpenIDConnect/Grant/CustomAuthCodeGrant.php(91): League\OAuth2\Server\Grant\AuthCodeGrant->validateAuthorizationRequest()\n#4 /home/ddfvd6qhit7y/public_html/vendor/league/oauth2-server/src/AuthorizationServer.php(163): OpenEMR\Common\Auth\OpenIDConnect\Grant\CustomAuthCodeGrant->validateAuthorizationRequest()\n#5 /home/ddfvd6qhit7y/public_html/src/RestControllers/AuthorizationController.php(504): League\OAuth2\Server\AuthorizationServer->validateAuthorizationRequest()\n#6 /home/ddfvd6qhit7y/public_html/oauth2/authorize.php(86): OpenEMR\RestControllers\AuthorizationController->oauthAuthorizationFlow()\n#7 {main}”}

OpenEMR.ERROR: AuthorizationController->oauthAuthorizationFlow() OAuthServerException {“hint”:“”,“message”:“Client authentication failed”,“payload”:{“error”:“invalid_client”,“error_description”:“Client authentication failed”,“message”:“Client authentication failed”},“trace”:“#0 /home/ddfvd6qhit7y/public_html/vendor/league/oauth2-server/src/Grant/AbstractGrant.php(290): League\OAuth2\Server\Exception\OAuthServerException::invalidClient()\n#1 /home/ddfvd6qhit7y/public_html/src/Common/Auth/OpenIDConnect/Grant/CustomAuthCodeGrant.php(101): League\OAuth2\Server\Grant\AbstractGrant->validateRedirectUri()\n#2 /home/ddfvd6qhit7y/public_html/vendor/league/oauth2-server/src/Grant/AuthCodeGrant.php(281): OpenEMR\Common\Auth\OpenIDConnect\Grant\CustomAuthCodeGrant->validateRedirectUri()\n#3 /home/ddfvd6qhit7y/public_html/src/Common/Auth/OpenIDConnect/Grant/CustomAuthCodeGrant.php(91): League\OAuth2\Server\Grant\AuthCodeGrant->validateAuthorizationRequest()\n#4 /home/ddfvd6qhit7y/public_html/vendor/league/oauth2-server/src/AuthorizationServer.php(163): OpenEMR\Common\Auth\OpenIDConnect\Grant\CustomAuthCodeGrant->validateAuthorizationRequest()\n#5 /home/ddfvd6qhit7y/public_html/src/RestControllers/AuthorizationController.php(504): League\OAuth2\Server\AuthorizationServer->validateAuthorizationRequest()\n#6 /home/ddfvd6qhit7y/public_html/oauth2/authorize.php(86): OpenEMR\RestControllers\AuthorizationController->oauthAuthorizationFlow()\n#7 {main}”,“redirectUri”:“”,“errorType”:“invalid_client”}

Dear Saeed,
TL/DR; Upgrade to Patch 3 over 7.0.2 and retry.

To describe more, I have found an issue on version 7.0.2 which might have affected you depending on the method you have used to install openemr.
Actually, there ought to exist a _rest_config.php file in the root of openemr folder as referenced by the line 22 of register-app.php (as of version 7.0.2, and line 34 in the patch 3 as shown in the picture).

I confirm that the above file does not exist in release 7.0.2 (windows zip file). But it will be added if you apply patch3 (elaborated in the photo again). I have not yet investigated the packages for other platforms (e.g. the tar.gz version for linux, etc) for the same flaw.

Kindly please verify whether your “openemr/interface/smart/register-app.php” references the “/openemr/_rest_config.php” using “require_once(“./…/…/_rest_config.php”);” syntax on the first few lines (probably 20 to 40) of the former mentioned file. Then kindly please verify existence of the latter mentioned file.