0

I am getting the Token from api call /V1/integration/customer/token I want to get the user id from this jwt token. How i can get it in magento2.4.5 ?

1
  • $token->getUserContext()->getUserId()) Oct 26, 2022 at 12:46

1 Answer 1

1

Inject \Magento\JwtUserToken\Model\Reader and then call read($token) on it.

In PHP8.1 this looks like

public funtion __construct(private \Magento\JwtUserToken\Model\Reader $jwtReader) {
  
}

public function test() {
    $context = $this->jwtReader->read($token);
    $userId = $context->getUserContext()->getUserId();
}


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.