【问题标题】:Authenticating domain users to SharePoint Online via ADFS通过 ADFS 向 SharePoint Online 验证域用户
【发布时间】:2017-04-18 07:33:14
【问题描述】:
我需要编写一个 C# 应用程序,该应用程序将连接到 SharePoint Online 文档库并允许用户从库中导入内容(文档库正在替换旧的网络驱动器)。我们的 Office 365 租赁使用本地 ADFS 服务器(完全联合身份)提供的 SSO 进行身份验证。
我在想,为了连接到文档库,我需要从 ADFS 服务器请求某种授权令牌,以便在连接到文档库时传递到 SharePoint Online 的登录 URL。不过,我以前从来没有做过这样的事情,所以我想知道这里是否有人做过类似的事情,或者对从哪里开始有什么好的建议?该应用程序只会在加入域的机器上运行,因此无需考虑离线场景。
非常感谢您的任何建议!
【问题讨论】:
标签:
c#
authentication
sharepoint
office365
adfs
【解决方案2】:
我设法让 ADFS 使用此代码颁发令牌:
public GenericXmlSecurityToken GetToken()
{
WS2007HttpBinding binding = new WS2007HttpBinding(SecurityMode.Transport);
binding.Security.Message.EstablishSecurityContext = false;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
WSTrustChannelFactory factory = new WSTrustChannelFactory((binding), new EndpointAddress(stsEndpoint));
factory.TrustVersion = TrustVersion.WSTrustFeb2005;
factory.Credentials.SupportInteractive = false;
var rst = new RequestSecurityToken
{
RequestType = RequestTypes.Issue,
AppliesTo = new EndpointReference(realm),
KeyType = KeyTypes.Bearer
};
IWSTrustChannelContract channel = factory.CreateChannel();
return channel.Issue(rst) as GenericXmlSecurityToken;
}
然后将其用于参数化我提交给 MS STS 服务器以进行身份验证的 SOAP 请求。完成后,我可以使用 HttpWebRequest 和 CookieContainer 从 SharePoint 获取 cookie,然后我使用此代码
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool InternetSetCookie(string url, string name, string data);
公开 InternetSetCookie 方法以保存用户会话的 cookie。