bitnami / vms

Bitnami VMs
https://bitnami.com
Other
206 stars 44 forks source link

[SuiteCRM] API OAuth2 issue, 500 response instead of token #509

Closed plochu closed 1 year ago

plochu commented 1 year ago

Platform

AWS

bndiagnostic ID know more about bndiagnostic ID

ddefa4cb-128f-ea8a-1755-f85dfae01865

bndiagnostic output

===== Begin of bndiagnostic tool output =====

? Resources: Found possible issues
✓ Connectivity: No issues found
✓ Mariadb: No issues found
✓ Processes: No issues found
? Apache: Found possible issues
✓ Php: No issues found

[Resources]

Your instance has little available RAM memory.

 total used free shared buff/cache available Mem: 954 561 67 0 326 219 Swap: 634 
131 503

You could try to increase your instance's memory. Please check your cloud provider's documentation for more information.

Press [Enter] to continue: [Apache]

Found recent error or warning messages in the Apache error log.

[Tue Nov 22 14:05:04.312388 2022] [proxy_fcgi:error] [pid 2156:tid 
139718918375168] [client **ip_address**:41704] AH01071: Got error 'PHP message: 
PHP Fatal error: Uncaught Error: Non-static method 
SugarOutfitters_API::get_default_payload() cannot be called statically in 
/bitnami/suitecrm/modules/AsteriskIntegration/outfitterslicense.php:543
Stack trace:
#0 /bitnami/suitecrm/modules/AsteriskIntegration/outfitterslicense.php(237): 
SugarOutfitters_API::call()
#1 /bitnami/suitecrm/modules/Aster [Tue Nov 22 14:07:32.854163 2022] 
[proxy_fcgi:error] [pid 2731:tid 139717659993856] [client **ip_address**:55704] 
AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Error: Non-static 
method SugarOutfitters_API::get_default_payload() cannot be called statically in 
/bitnami/suitecrm/modules/AsteriskIntegration/outfitterslicense.php:543
Stack trace:
#0 /bitnami/suitecrm/modules/AsteriskIntegration/outfitterslicense.php(237): 
SugarOutfitters_API::call()
#1 /bitnami/suitecrm/modules/Aster [Tue Nov 22 14:10:22.300575 2022] 
[proxy_fcgi:error] [pid 2731:tid 139718943553280] [client **ip_address**:52314] 
AH01071: Got error 'PHP message: PHP Fatal error: Uncaught Error: Non-static 
Press [Enter] to continue:
method SugarOutfitters_API::get_default_payload() cannot be called statically in 
/bitnami/suitecrm/modules/AsteriskIntegration/outfitterslicense.php:543
Stack trace:
#0 /bitnami/suitecrm/modules/AsteriskIntegration/outfitterslicense.php(237): 
SugarOutfitters_API::call()
#1 /bitnami/suitecrm/modules/Aster

Please check the following guide to troubleshoot server issues:

https://docs.bitnami.com/general/apps/wordpress/troubleshooting/debug-erro rs-apache/

===== End of bndiagnostic tool output =====

bndiagnostic was not useful. Could you please tell us why?

still can't find issue source

Describe your issue as much as you can

Hi, here is the case :slight_smile:

Fresh installation in AWS cloud using Bitnami SuiteCRM. Everything works fine but not API. All steps checked with GUIDE

When I call endpoint https://xxx.xxx.xxx.xxx/Api/access_token

I get 500 response with: {“error”:“unknown_error”,“message”:"It was not possible to parse your key, reason: "}

There are no errors in Apache error_log. Here is dump from suitecrm.log

Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Hook called: OAuth2Clients::before_retrieve
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Retrieve OAuth2Clients : SELECT oauth2clients.* FROM oauth2clients WHERE oauth2clients.id = ‘43c68236-a52e-12ac-0108-637ca367a023’ AND oauth2clients.deleted=0
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Limit Query:SELECT oauth2clients.* FROM oauth2clients WHERE oauth2clients.id = ‘43c68236-a52e-12ac-0108-637ca367a023’ AND oauth2clients.deleted=0 Start: 0 count: 1
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query:SELECT oauth2clients.* FROM oauth2clients WHERE oauth2clients.id = ‘43c68236-a52e-12ac-0108-637ca367a023’ AND oauth2clients.deleted=0 LIMIT 0,1
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query Execution Time:0.00023603439331055
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] get_user_array query: SELECT id, first_name, last_name, user_name FROM users WHERE 1=1 ORDER BY user_name ASC
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query:SELECT id, first_name, last_name, user_name FROM users WHERE 1=1 ORDER BY user_name ASC
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query Execution Time:0.00012993812561035
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Hook called: OAuth2Clients::after_retrieve
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Hook called: OAuth2Tokens::before_save
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query:INSERT INTO oauth2tokens (id,name,date_entered,date_modified,deleted,token_is_revoked,token_type,access_token_expires,access_token,grant_type,client,assigned_user_id)
VALUES (‘6e55674f-6e36-19df-0460-637cab39502e’,’’,‘2022-11-22 10:57:44’,‘2022-11-22 10:57:44’,0,0,’’,‘2022-11-22 11:57:44’,‘8ea3705187dcb239caa9582aea739cb6e4b657e271b3b8867a7b5cc9b5c317bad605fbe7ece2e9a8’,’’,‘43c68236-a52e-12ac-0108-637ca367a023’,‘6ff18e1b-a2bd-09bd-d9bd-637caab54b15’)
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query Execution Time:0.0042288303375244
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] SecuritySuite: Get SecuritySuite Enabled Modules: SELECT lhs_module, rhs_module FROM relationships WHERE deleted=0 AND (lhs_module = ‘SecurityGroups’ OR rhs_module=‘SecurityGroups’)
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query:SELECT lhs_module, rhs_module FROM relationships WHERE deleted=0 AND (lhs_module = ‘SecurityGroups’ OR rhs_module=‘SecurityGroups’)
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query Execution Time:0.00080585479736328
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] SecuritySuite: Get SecuritySuite Enabled Modules: SELECT lhs_module, rhs_module FROM relationships WHERE deleted=0 AND (lhs_module = ‘SecurityGroups’ OR rhs_module=‘SecurityGroups’)
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query:SELECT lhs_module, rhs_module FROM relationships WHERE deleted=0 AND (lhs_module = ‘SecurityGroups’ OR rhs_module=‘SecurityGroups’)
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query Execution Time:0.00032901763916016
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] SecuritySuite: Get SecuritySuite Enabled Modules: SELECT lhs_module, rhs_module FROM relationships WHERE deleted=0 AND (lhs_module = ‘SecurityGroups’ OR rhs_module=‘SecurityGroups’)
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query:SELECT lhs_module, rhs_module FROM relationships WHERE deleted=0 AND (lhs_module = ‘SecurityGroups’ OR rhs_module=‘SecurityGroups’)
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query Execution Time:0.00074315071105957
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] SecuritySuite: Get SecuritySuite Enabled Modules: SELECT lhs_module, rhs_module FROM relationships WHERE deleted=0 AND (lhs_module = ‘SecurityGroups’ OR rhs_module=‘SecurityGroups’)
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query:SELECT lhs_module, rhs_module FROM relationships WHERE deleted=0 AND (lhs_module = ‘SecurityGroups’ OR rhs_module=‘SecurityGroups’)
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query Execution Time:0.00010585784912109
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Hook called: OAuth2Tokens::after_save
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Creating new instance of hook class AOD_LogicHooks without parameters
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Hook called: AOD_Index::before_retrieve
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Retrieve AOD_Index : SELECT aod_index.* FROM aod_index WHERE aod_index.id = ‘1’ AND aod_index.deleted=0
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Limit Query:SELECT aod_index.* FROM aod_index WHERE aod_index.id = ‘1’ AND aod_index.deleted=0 Start: 0 count: 1
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query:SELECT aod_index.* FROM aod_index WHERE aod_index.id = ‘1’ AND aod_index.deleted=0 LIMIT 0,1
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query Execution Time:0.00014805793762207
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] SugarBean[AOD_Index].load_relationships, Loading relationship (assigned_user_id).
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] SugarBean.load_relationships, failed Loading relationship (assigned_user_id)
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] SugarBean[AOD_Index].load_relationships, Loading relationship (assigned_user_id).
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] SugarBean.load_relationships, failed Loading relationship (assigned_user_id)
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Hook called: AOD_Index::after_retrieve
Tue Nov 22 10:57:44 2022 [3390][-none-][DEPRECATED] AOD Lucene search is deprecated since v7.12.0
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Creating new instance of hook class SuiteCRM\Search\ElasticSearch\ElasticSearchHooks without parameters
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Creating new instance of hook class AssignGroups without parameters
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Creating new instance of hook class AOW_WorkFlow without parameters
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query:SELECT id FROM aow_workflow WHERE aow_workflow.flow_module = ‘OAuth2Tokens’ AND aow_workflow.status = ‘Active’ AND (aow_workflow.run_when = ‘Always’ OR aow_workflow.run_when = ‘On_Save’ OR aow_workflow.run_when = ‘Create’) AND aow_workflow.deleted = 0
Tue Nov 22 10:57:44 2022 [3390][-none-][INFO] Query Execution Time:0.00025796890258789
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Hook called: ::server_round_trip
Tue Nov 22 10:57:44 2022 [3390][-none-][DEBUG] Calling MySQLi::disconnect()

Where should I look for error?

BTW. When I use “wrong” credentials I get: for wrong client id (error 500) {"error":"unknown_error","message":"OAuth2Clients module with id 43c68236-a52e-12ac-0108-637ca367a023a is not found"}

for wrong client_secret (error 401) {"error":"invalid_client","message":"Client authentication failed"}

So this API works fine, there is some server processing problem. Also I can see from SuiteCRM console that token has ben generated.

jotamartos commented 1 year ago

Hi @plochu,

Thank you for using Bitnami. This question is related to the application, its configuration and the different plugins/extensions you are using and it's out of the scope of this support forum. We suggest you ask in the official forums of SuiteCRM to get more information about the errors you are getting and how to troubleshoot the issue.

https://community.suitecrm.com/

plochu commented 1 year ago

I'm also trying to get help from SuiteCRM support. I fully understand you but in my opinion this issue can be related with Bitnami package. Other system that has been deployed manually from very beginning with default settings doesn't have this issue.

jotamartos commented 1 year ago

You are right, and this may be related to the packaging but please note that this is a very specific issue and the SuiteCRM's team should help you debug the issue or at least let you know how to troubleshoot it. We include some tests in our pipeline to ensure the application works after configuring it but we can't control all scenarios. We will be more than happy to change anything wrong in our packaging if required, but as we do not have complete control over the application, we can't provide support here and if the app doesn't provide the exact error, it's even harder for us.

plochu commented 1 year ago

Please be aware that this situation appears after fresh install of your stack, without any custom modules ect.

The asterisk integration module errors that yu can see in report are inrelavant and to be sure I also confirmed issue starting new instance without any additional changes after "clean" installation from AMI.

The only thing made by me is generating keys in {{suitecrm.root}}/Api/V8/OAuth2 directory. And of course setting proper chown / chmod. This is a must be for API v8 to work.

BTW. I think that you can automaticly generate keys above during installation process.

BTW 2. I reproduced similar issue to described on other system. API was working fine but after upgrade php7 to php8 we recieve 500 error in exacly the same point. This could be completly coincidence but also this could be a good lead. I will try to verify this.

jotamartos commented 1 year ago

The PHP version change is a good lead. They do not mention anything regarding issues with PHP 8.0 in the documentation but maybe they are not aware of them or the documentation is outdated

https://docs.suitecrm.com/developer/api/developer-setup-guide/requirements/

plochu commented 1 year ago

You are very right. The question is whether you will engage in it. At this point, your product is not properly prepared for basic work.

I understand that you also have to look at it from the business side and the popularity of the stack. I also know that working with the SuiteCRM community can be difficult.

jotamartos commented 1 year ago

Please note that using PHP 7.x is not possible anymore as they are not supported and we will be introducing bugs and security issues in the product.

https://www.php.net/supported-versions.php

If there is an issue with PHP, this is something the SuiteCRM's developers need to fix. We can't do anything right now to solve this and there was not any note/warning in the documentation that prevented us to update the solution to PHP 8.x

github-actions[bot] commented 1 year ago

This Issue has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thanks for the feedback.

github-actions[bot] commented 1 year ago

Due to the lack of activity in the last 5 days since it was marked as "stale", we proceed to close this Issue. Do not hesitate to reopen it later if necessary.

teemk commented 1 year ago

Guys, we experience identical problem on Bitnami-suitecrm8 stack (PHP 8.1)

jotamartos commented 1 year ago

Hi @teemk,

As I mentioned above, this seems to be a problem in the application. Please contact them to troubleshoot the issue.

Thanks

sunnykumar347 commented 7 months ago

Hi @teemk @plochu , Incase this issue is not resolved.

Issue is related to PHP version upgrade. And specifically introduction of class OpenSSLAsymmetricKey.

Suitecrm is using lcobucci/jwt package which they use to sign the oauth keys.

I changed this file to resolve this issue:

vendor/lcobucci/jwt/src/Signer/OpenSSL.php

grinono commented 2 months ago

i'm having the same issue. @sunnykumar347 what is the change you made after fresh install?


vendor/lcobucci/jwt/src/Signer/OpenSSL.php

< this file does not exist in my bitnami suiteCRM instance 8.6.2
sunnykumar347 commented 2 months ago

@grinono You might not have this issue, because 8.6.2 already using PHP 8 as default version which means lcobucci/jwt would be latest for it.

Please check other things.

BTW file is still there, you can see it after installing dependencies using composer install

grinono commented 2 months ago

@sunnykumar347 i'm not seeing the file. And yes i ran the composer install command.

my logs show

PHP Fatal error:  Uncaught LogicException: Invalid key supplied in /bitnami/suitecrm/vendor/league/oauth2-server/src/CryptKey.php:67

stack trace

Stack trace:
#0 /bitnami/suitecrm/public/legacy/Api/V8/Config/services/middlewares.php(48): League\OAuth2\Server\CryptKey->__construct()
#1 /bitnami/suitecrm/vendor/pimple/pimple/src/Pimple/Container.php(122): Api\Core\Resolver\ConfigResolver::{closure}()
#2 /bitnami/suitecrm/vendor/slim/slim/Slim/Container.php(109): Pimple\Container->offsetGet()
#3 /bitnami/suitecrm/public/legacy/Api/V8/Config/routes.php(17): Slim\Container->get()
#4 /bitnami/suitecrm/vendor/slim/slim/Slim/RouteGroup.php(25): Api\Core\Loader\RouteLoader->{closure}()
#5 /bitnami/suitecrm/vendor/slim/slim/Slim/App.php(272): Slim\RouteGroup->__invoke()
#6 /bitnami/suitecrm/public/legacy/Api/V8/Config/routes.php(132): Slim\App->group()
#7 /bitnami/suitecrm/public/legacy/Api/Core/Loader/RouteLoader.php(22): require('...')
#8 /bitnami/suitecrm/public/legacy/Api/Core/app.php(26): Api\Core\Loader\RouteLoader->configureRoutes()
#9 /bitnami/suitecrm/public/legacy/Api/index.php(11): require_once('...')
#10 /bitnami/suitecrm/public/index.php(61): require('...')
#11 {main}