I have a multi-tenant Azure AD web application set up. This represents a scheduled task that needs to get a list of Site Collections from each one of (the web app's) SharePoint Online Tenants.
I am trying to achieve this by using CSOM as detailed in this blog post from Sahil Malik.
The first step in the code in the blog post is a call to this method from the TokenHelper class:
public static OAuth2AccessTokenResponse GetAppOnlyAccessToken( string targetPrincipalName, string targetHost, string targetRealm)
What should I put in place of the
targetPrincipalName? Where do I obtain this value for each one of my tenants?
targetHostbe the admin URL for each tenant? For example: "http://tenant1-admin.onmicrosoft.com/"?
Should my 'targetRealm' be null?
Having read through parts of the implementation of the
GetAppOnlyAccessToken() method, I've realized I've been missing several
appSettings that are required for it to work.
So far I've gathered the following but am still getting "(400) Token request failed." from SharePoint Online:
<appSettings> <!-- Guid to the left of @ in App Identifier (?) --> <add key="ClientId" value="..." /> <!-- Not sure how to obtain this as: --> <add key="ClientSecret" value="..." /> <!-- Guid to the right of @ in App Identifier (?) --> <add key="Realm" value="..."/> </appSettings>
Am I missing any other appSettings? Am I correctly populating the ones above?