如何将用户凭据从控制台传递到 SharePoint Online? [英] How do I pass user credentials from the console to SharePoint Online?

查看:45
本文介绍了如何将用户凭据从控制台传递到 SharePoint Online?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用来自控制台可执行文件的上下文令牌连接 SharePoint 2013 Online 网站.但是,它给了我错误 远程服务器返回错误:(403) Forbidden.

I am trying to connect SharePoint 2013 Online website using a Context Token from a console executable. However, it is giving me error The remote server returned an error: (403) Forbidden.

这是代码片段:

string spurl = ConfigurationManager.AppSettings["Sharepoint_URL"].ToString();
using (ClientContext context = new ClientContext(spurl))
{
    context.Credentials = new NetworkCredential("username", "password", "domain");
    context.ExecuteQuery();
    Web web = context.Web;
    context.Load(web);
    context.ExecuteQuery();
    Console.WriteLine(context.Web.Title);
 }               
 Console.ReadKey();

如何与 SharePoint Online 建立连接?它是否仅支持基于声明的身份验证?

How can I make a connection with SharePoint Online? Does it only support claims-based authentication?

推荐答案

我认为您尝试进行身份验证的方法已经过时.SharePoint 2013 客户端对象模型现在有一个名为 SharePointOnlineCredentials 的类,它抽象了所有乏味的 cookie 容器内容.例如:

I think the method with which you are trying to authenticate is outdated. The SharePoint 2013 Client Object Model now has a class called SharePointOnlineCredentials which abstracts away all the tedious cookie container stuff. E.g.:

using (ClientContext clientContext = new ClientContext("https://yoursite.sharepoint.com/"))  
{  
    SecureString passWord = new SecureString();
    clientContext.Credentials = new SharePointOnlineCredentials("loginname@yoursite.onmicrosoft.com", passWord);
    Web web = clientContext.Web;
    clientContext.Load(web);
    clientContext.ExecuteQuery();
    Console.WriteLine(web.Title);
    Console.ReadLine();
} 

请参阅此链接了解更多信息:https://sharepoint.stackexchange.com/questions/83985/access-the-sharepoint-online-webservice-from-a-console-application

Please refer to this link for more information: https://sharepoint.stackexchange.com/questions/83985/access-the-sharepoint-online-webservice-from-a-console-application

这篇关于如何将用户凭据从控制台传递到 SharePoint Online?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆