0

di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <type name="Magento\Integration\Model\CustomerTokenService">
        <plugin name="segment_logout_plugin" type="New\Hm\Plugin\RevokeCustomerToken" />
    </type>
</config>

Plugin

<?php

namespace New\Hm\Plugin;

class RevokeCustomerToken
{

    protected $logger;
    public function __construct(\Psr\Log\LoggerInterface $logger)
    {
        $this->logger = $logger;
    }
    public function afterRevokeCustomerAccessToken(\Magento\Integration\Model\CustomerTokenService $subject, $result,$customerId) {

        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/RevokeCustomerToken.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info($customerId);
    }

}

I am trying to add a afterplugin on revokeCustomerAccessToken() from app/code/Magento/Integration/Api/CustomerTokenServiceInterface.php

But it does not seems to be working. Any correction needed ?

1

1 Answer 1

0

You can plugin the interface Magento\Integration\Api\CustomerTokenServiceInterface instead of the implementation class Magento\Integration\Model\CustomerTokenService which you have tried to pluginize

it will work not tested though

di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Integration\Api\CustomerTokenServiceInterface">
        <plugin name="segment_logout_plugin" type="New\Hm\Plugin\RevokeCustomerToken" />
    </type>
</config>

New\Hm\Plugin\RevokeCustomerToken.php

<?php

namespace New\Hm\Plugin;

class RevokeCustomerToken
{

    protected $logger;
    public function __construct(\Psr\Log\LoggerInterface $logger)
    {
        $this->logger = $logger;
    }
    
    /**
     * Revoke token by customer id.
     *
     * The function will delete the token from the oauth_token table.
     *
     * @param CustomerTokenServiceInterface $subject
     * @param int $customerId
     *
     * @return bool
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function afterRevokeCustomerAccessToken(CustomerTokenServiceInterface $subject, $customerId)
    {
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/RevokeCustomerToken.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info($customerId);
        return $customerId;
    }

}
3

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.