目前,我可以使用用户 ID 和密码访问共享点列表,如下所示。但想了解如何使用客户端 ID 和客户端密码访问列表?
string siteUrl = "https://xyz.sharepoint.com/sites/MyList/";
ClientContext clientContext = new ClientContext(siteUrl);
string username = ConfigurationManager.AppSettings["username"];
string password = ConfigurationManager.AppSettings["password"];
System.Security.SecureString passWord = new System.Security.SecureString();
foreach (char c in password.ToCharArray())
{
passWord.AppendChar(c);
}
clientContext.Credentials = new SharePointOnlineCredentials(username, passWord);
Web oWebsite = clientContext.Web;
ListCollection collList = oWebsite.Lists;
clientContext.Load(collList);
clientContext.ExecuteQuery();
您可以使用GetAppOnlyAuthenticatedContext
PnP CSOM 核心的方法。
之后您可以使用如下代码:
string siteUrl = "https://xyz.sharepoint.com/sites/MyList/";
string clientId = "<client-id>";
string clientSecret = "<client-secret>";
using (var clientContext = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl,clientId,clientSecret))
{
Web oWebsite = clientContext.Web;
ListCollection collList = oWebsite.Lists;
clientContext.Load(collList);
clientContext.ExecuteQuery();
}
要添加 PnP CSOM 核心,请转到项目参考 > 管理 nuget 包。
添加 SharePointPnPCoreOnline 包。
参考 -使用 PnP 身份验证管理器对 SharePoint 进行身份验证 http://www.ktskumar.com/2016/05/authenticate-sharepoint-using-pnp-authentication-manager/
在公共网络上公开您的 SharePoint Online 信息 https://ypcode.wordpress.com/2017/05/11/expose-on-public-web-your-sharepoint-online-information/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)