I just want to confirm that I'm not missing something here. I'm working on a provisioning app that uses Add-in Only permissions to execute a timer job in SharePoint 2016 On-Premises. In typical Add-in development with Visual Studio and F5 debugging, there is no need to use AppRegNew.aspx to register an application with SharePoint as the ClientId and Secret are generated at runtime.
However, I am running into issues using F5 debugging when calling the TokenHelper.GetAppOnlyAccessToken and job.UseAppOnlyAuthentication(ClientId,ClientSecret) methods. Both throw errors. A couple of questions:
- Do I need to pre-register the app with AppRegNew.aspx in order to use Add-in Only Authentication? Or is this unexpected behavior?
- I noticed that alll of the samples on GitHub for async provisioning use Add-in Only Authentication; is it possible to use Network Credential authentication when creating the Tenant client context? Relevant code below:
string realm = TokenHelper.GetRealmFromTargetUrl(webUri);
var token = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, webUri.Authority, realm).AccessToken;
using (var ctx = TokenHelper.GetClientContextWithAccessToken(webFullUrl.ToString(), token))