I have an SP app, which I am hoping to release to the store.
The last thing I want to implement in it is a licence check, which I am doing on the server side (C#).
I found that to do this I need to first retrieve the current licences from SharePoint, which I am trying to do with this code:
ClientResult<AppLicenseCollection> licenseCollection = Utility.GetAppLicenseInformation(clientContext, productId);
clientContext.Load(clientContext.Web);
clientContext.ExecuteQuery();
However executing this code gives me an error: The remote server returned an error: (403) Forbidden.
I tried running this with various permissions granted to the app (up to full control over web/site/tenant) still with the same error.
Does anyone know what's missing?, I'm taking the product ID from the app catalog and the context seems ok, as it returns results for other types of requests.
Ok, I've got it returning the collection of licences. It looks like the context was incorrectly initialised after some of my recent tweaks and the Read Web permissions seems to be enough to load the licences.
However what I'm seeing now is that the licence collection I'm getting is empty. My app is not in store yet and I've only deployed it to my app catalog, does it need to be in store to get the actual licence returned? If so what's the best way forward, I don't really want to release an unfinished app.
Update: I was able to upload a test licence using SPAppLicenseHelper.GenerateTestToken from this project: https://code.msdn.microsoft.com/officeapps/SharePoint-2013-Import-f5f680a6/