C# SharePoint联机身份验证失败

C# SharePoint联机身份验证失败,c#,authentication,sharepoint,office365,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-wsse

我有一个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>
字符串。SharePointOnlineAuthenticationRequest

这是我发送的SOAP请求。在运行时替换“$(用户名)”、“$(密码)”和“$(地址)”令牌

<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>

http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue
http://www.w3.org/2005/08/addressing/anonymous
https://login.microsoftonline.com/extSTS.srf
$(用户名)
$(密码)
$(地址)
http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKey
http://schemas.xmlsoap.org/ws/2005/02/trust/Issue
urn:oasis:names:tc:SAML:1.0:assertion

如果用户的名称最近发生了更改,我发现名称更改后ADFS声明丢失的问题:

<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>