I am developing .NET VSTO Addin, and would like to publish natively to Sharepoint Online using the SharePoint PnP library. It is not clear to me how to use the AuthenticationManager to get a ClientContext using the current logged in user's Azure AD credentials (assuming this is possible).
I have registered the VSTO Addin with Azure AD, and was hoping that the AuthenticationManager could be called without explictly setting the username and password, per the following code:
using (ClientContext context = authenticationManager.GetContext(site, userPrincipal, userPasswordSecure))
{
ClientSidePage myPage = new ClientSidePage(context);
myPage.Save("Foo.aspx");
myPage.Publish();
}
Basically I am looking for an overloaded method that only needs the site paramter to be passed. This avoids the user having to explicitly set their username and password.
Thanks and regards, Andrew
Please try
GetAzureADAccessTokenAuthenticatedContext(String, String)
Method.For more information about getting access on behalf of a user, see here.