简体   繁体   中英

Sharepoint Azure AD authentication

How can I access documents from SharePoint library path using C# console application. Configured SharePoint on premise authentication with Azure AD for remote access.

Before configured, C# console application can access documents from SharePoint library path using SharePoint Client Object Model (CSOM).

Here is sample code:

ClientContext context = new ClientContext(RootLibraryPath);
SecureString passWord = new SecureString();
foreach (char c in Password.ToCharArray()) passWord.AppendChar(c);
context.Credentials = new NetworkCredential(UserName, passWord);
context.ExecuteQuery();

Web web = context.Web;
CamlQuery query = new CamlQuery();
query.ViewXml = "<View Scope='RecursiveAll'>" +
                   "<Query>" +
                   "</Query>" +
                 "</View>";

List list = web.Lists.GetByTitle(libraryName);
ListItemCollection items = list.GetItems(query);
context.Load(items);
context.ExecuteQuery();

You could call SharePoint Online APIs (via REST or CSOM) with Azure Active Directory Apps . To call APIS secured by Azure AD , your app must acquire an access token from Azure Active Directory (Azure AD), Microsoft's cloud identity service.

Please firstly refer to this document for integrating applications with Azure Active Directory . And then use Azure Active Directory Authentication Library (ADAL) to easily authenticate users to cloud or on-premises Active Directory (AD), and obtain access tokens for securing API calls. Also here and here are documents for how to use CSOM with Azure Active Directory Apps .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM