It's more a core logic issue than a technical issue!

I created one new table for admin_user: admin_user_config_data


And, like in core_config_data, in this new table will be stored the data from the specific admin_user.

I tried to create a new scope, but It's very complicated, and looking the code I realized that magento create a new cache from every scope and every time that I need to change the config.

Aways that I need to run this line:


Well. Than I created the plugin below that search for the config path in my new table:


<type name="Magento\Framework\App\Config\ScopeConfigInterface">
    <plugin name="Mine_User_ScopeConfigInterface" type="Mine\User\Plugin\ScopeConfig" />


class ScopeConfig
    public function __construct(
        \Mine\User\Model\ResourceModel\UserConfigData\CollectionFactory $userConfigDataCollectionFactory,
        \Magento\Authorization\Model\UserContextInterface $userContext
        $this->_userConfigDataCollectionFactory = $userConfigDataCollectionFactory;
        $this->_userContext = $userContext;

    public function afterGetValue(
        \Magento\Framework\App\Config\ScopeConfigInterface $subject,
        $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
        $scopeCode = null
        if ($this->_userContext && $this->_userContext->getUserId()) {
            $userConfigData = $this->_userConfigDataCollectionFactory->create()
                ->addFieldToFilter('path', $path)
                ->addFieldToFilter('user_id', $this->_userContext->getUserId())

            if ($userConfigData->getId()) {
                return $userConfigData->getValue();

        return $result;

But if I do this, my API returns the message:

Consumer is not authorized to access %resources

Without the UserContextInterface in the constructor the API works normally.

Anyone have any idea of how I can get the config stored in the admin_user_config_data after the value provided by the scopeConfig and with current logged in user? (The login is by api token provided by V1/integration/admin/token)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.