Skip to content

"User type not defined" error when using OAuth1 authentication on guest cart endpoints #40382

@karitham

Description

@karitham

Preconditions and environment

  • Magento version: 2.4.7
  • Backpressure enforcement enabled (sales/backpressure/enabled = 1)
  • OAuth1 integration configured with valid consumer key/secret
  • REST API webapi_rest area

Steps to reproduce

  1. Enable backpressure
  2. Create a guest cart via REST API: POST /rest/V1/guest-carts
  3. Add products and set shipping information
  4. Attempt to place order using OAuth1 authentication:
    POST /rest/V1/guest-carts/{cartId}/payment-information
    Authorization: OAuth....
    Content-Type: application/json
    
    {
      "email": "[email protected]",
      "paymentMethod": {"method": "checkmo"}
    }
    

Expected result

Order should be placed successfully with a valid order ID returned, or appropriate validation errors if payment/shipping data is invalid.

Actual result

API returns error:

{"message":"User type not defined"}

Exception is thrown from Magento\Authorization\Model\IdentityProvider::fetchIdentityType() at line 65.

Additional information

I am an API client integrating against major hosted magento2 websites and we recently started having this error; I do not host or own myself a magento2 instance.

I'm not that proficient at PHP so bear with my analysis here:

Root Cause:

The IdentityProvider class only maps two user types for backpressure rate limiting:

  • USER_TYPE_CUSTOMERIDENTITY_TYPE_CUSTOMER
  • USER_TYPE_ADMINIDENTITY_TYPE_ADMIN

However, when OAuth1 authentication is used, the OauthUserContext returns USER_TYPE_INTEGRATION (value 1), which has no mapping.

This causes the RuntimeException.

Affected code:

app/code/Magento/Authorization/Model/IdentityProvider.php lines 24-27:

private const USER_CONTEXT_IDENTITY_TYPE_MAP = [
    UserContextInterface::USER_TYPE_CUSTOMER => ContextInterface::IDENTITY_TYPE_CUSTOMER,
    UserContextInterface::USER_TYPE_ADMIN => ContextInterface::IDENTITY_TYPE_ADMIN
    // Missing: USER_TYPE_INTEGRATION mapping
];

Release note

Fixed "User type not defined" error when calling guest cart REST API endpoints with OAuth1 authentication and backpressure enabled.

Triage and priority

  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Ready for Confirmation

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions