GetAzureADWebApplicationAuthenticatedContext() public method

Returns a SharePoint ClientContext using Azure Active Directory authentication. This requires that you have a Azure AD Web Application registered. The user will not be prompted for authentication, the current user's authentication context will be used by leveraging ADAL.
public GetAzureADWebApplicationAuthenticatedContext ( String siteUrl, String>.Func accessTokenGetter ) : ClientContext
siteUrl String Site for which the ClientContext object will be instantiated
accessTokenGetter String>.Func The AccessToken getter method to use
return ClientContext
Exemplo n.º 1
0
        public static void BrowseFilesLibrary()
        {
            // Create a PnP AuthenticationManager object
            AuthenticationManager am = new AuthenticationManager();

            // Authenticate against SPO with a delegated access token
            using (ClientContext context = am.GetAzureADWebApplicationAuthenticatedContext(
                O365ProjectsAppContext.CurrentSiteUrl, (url) => {
                    return (MicrosoftGraphHelper.GetAccessTokenForCurrentUser(url));
                }))
            {
                Web web = context.Web;
                var targetLibrary = web.GetListByTitle(O365ProjectsAppSettings.LibraryTitle);

                context.Load(targetLibrary.RootFolder, 
                    fld => fld.ServerRelativeUrl,
                    fld => fld.Files.Include(f => f.Title, f => f.ServerRelativeUrl));
                context.ExecuteQueryRetry();

                foreach (var file in targetLibrary.RootFolder.Files)
                {
                    // Handle each file object ... this is just a sample ...
                }
            }
        }