c# - SharePoint Online 身份验证失败

标签 c# authentication sharepoint office365 sharepoint-online

我有一个 C# 应用程序,它使用 Web 请求向 SharePoint Online 进行身份验证。它对我很有用,但其他人收到以下错误:

<?xml version="1.0" encoding="utf-8" ?><S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wst="http://schemas.xmlsoap.org/ws/2005/02/trust" xmlns:psf="http://schemas.microsoft.com/Passport/SoapServices/SOAPFault">
  <S:Body>
    <S:Fault>
      <S:Code>
        <S:Value>S:Sender</S:Value>
        <S:Subcode>
          <S:Value>wst:FailedAuthentication</S:Value>
        </S:Subcode>
      </S:Code>
      <S:Reason>
        <S:Text xml:lang="en-US">Authentication Failure</S:Text>
      </S:Reason>
      <S:Detail>
        <psf:error>
          <psf:value>0x80048821</psf:value>
          <psf:internalerror>
            <psf:code>0x80041034</psf:code>
            <psf:text>The specified member name is either invalid or empty.&#x000D;&#x000A;</psf:text>
          </psf:internalerror>
        </psf:error>
      </S:Detail>
    </S:Fault>
  </S:Body>
</S:Envelope>

这个错误是什么意思?我很确定他们输入了正确的用户名和密码。是否有我可以在某处找到的 SharePoint Online 错误代码列表可以帮助我确定问题?

这是我的 C# 代码:

var request = (HttpWebRequest)WebRequest.Create(@"https://login.microsoftonline.com/extSTS.srf");
request.AllowAutoRedirect = false;
request.ContentType = @"application/json; odata=verbose";
request.CookieContainer = this.CookieContainer;
request.Method = @"POST";
request.UserAgent = @"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";

string soapRequest = Strings.SharePointOnlineAuthenticationRequest
    .Replace(@"$(UserName)", this.UserName)
    .Replace(@"$(Password)", this.Password)
    .Replace(@"$(Address)", this.SiteUrl);
byte[] contentBytes = new ASCIIEncoding().GetBytes(soapRequest);
request.ContentLength = contentBytes.Length;
using (var requestStream = request.GetRequestStream())
{
    requestStream.Write(contentBytes, 0, contentBytes.Length);
}

Strings.SharePointOnlineAuthenticationRequest

这是我发送的 SOAP 请求。 “$(UserName)”、“$(Password)”和“$(Address)”标记在运行时被替换。

<value>
  <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
  <a:Action s:mustUnderstand="1=">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
  <a:ReplyTo>
  <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
  </a:ReplyTo>
  <a:To s:mustUnderstand="1=">https://login.microsoftonline.com/extSTS.srf</a:To>
  <o:Security s:mustUnderstand="1=" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
  <o:UsernameToken>
  <o:Username>$(UserName)</o:Username>
  <o:Password>$(Password)</o:Password>
  </o:UsernameToken>
  </o:Security>
  </s:Header>
  <s:Body>
  <t:RequestSecurityToken xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust">
  <wsp:AppliesTo xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
  <a:EndpointReference>
  <a:Address>$(Address)</a:Address>
  </a:EndpointReference>
  </wsp:AppliesTo>
  <t:KeyType>http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey</t:KeyType>
  <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
  <t:TokenType>urn:oasis:names:tc:SAML:1.0:assertion</t:TokenType>
  </t:RequestSecurityToken>
  </s:Body>
  </s:Envelope>
</value>

最佳答案

最近是否更改了用户名,我看到过名称更改后 ADFS 声明丢失的问题:see techet article AD FS 2.0: Claims Are Missing From The Output Claim Set After A User's Name Has Changed

关于c# - SharePoint Online 身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34052291/

相关文章:

web-services - 使用没有托管代码的 Infopath 表单在 Sharepoint 上使用 UpdateListItems webbservice

sharepoint - 项目 myProjectWeb : Unable to find version '3.0.1' of package 'AppForSharePoint16WebToolkit' 的 NuGet 包还原失败

php - 将用户存储为对象是否有意义?

php - Laravel AJAX 请求发布错误代码 : 419 after session id changed when logging in using laravel auth

sharepoint - 将自定义 Web 服务部署到 sharepoint 服务器(2007/2010)?

c# - asp.net gridview动态绑定(bind)

jakarta-ee - Java EE Web应用程序“记住我”自动登录完成了吗?

c# - 在Datagridview中添加下拉框

c# - 如何在 Visual Studio 中创建 MSI 安装程序?

c# - 获取天气的 Web 服务