Recently, we were working on calling SharePoint API from plugin. While getting the access token we received the following error: “Access denied. You do not have permission to perform this action or access this resource”.
To fix this issue, we gave appropriate permission to the Application we had created in SharePoint for Server to Server authentication.
Below is the permission XML:
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl"/>
</AppPermissionRequests>
We can follow the steps mentioned here to give the above permission.
Hope it helps !!