We have a issue and want to limit permission each roles.
Do we have any way to make Graphql can set permission roles as Rest API?
EX: Admin token with roles "sales", they only access Graphql APIs of Sales.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI wasn't able to find anything cleary documented regarding this, so here is what I used. Not sure if it's the best way so please let me know!
In resolver class or interface that handles the graphql request:
//add the dependency to your constructor
Magento\Framework\AuthorizationInterface
...
//use the authorization to check the resource id set in acl.xml
// throw exception (or you could return false or do something else)
if (!$this->authorization->isAllowed('Your_Resource_Id')) {
throw new \Magento\Framework\Webapi\Exception(__('Forbidden'), 0, 403);
}