Forum Discussion
Create Sharing Link using CSOM/PnP.Framework
Are you using SharePoint App Only Context? or are you using Azure AD App Permission to connect?
If you are using SharePoint App Only Context then you need to make sure two things
- Make sure that you have "AllowAppOnlyPolicy" value to true while you have given permission via _layouts/appinv.aspx. If you are not suer about it then you can reassign permission in the site collection
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
</AppPermissionRequests>
- Make sure that DisableCustomAppAuthentication is set to False in your Tenant (Important: Once you apply this change it can take maximum 24 hours to reflect). You can use Set-SPOTenant to do so.
If you are using Azure AD App Registration then make sure that you have given Application Level Permission in your App as shown in below
In case of Share Document code, Below is the sample where I am using Modern API to do so
https://github.com/kavaghela/sharedocumentspapi
Hope it will helpful to you and if so then Please mark my response as Best Response & Like to help others in this community
Can you make sure that you have given correct permission in Azure AD App Registration? as you are using Client Id and Secret key you need to provide application permission.