CRM Online 2015 API 通过 PHP - securityToken 问题

CRM Online 2015 API via PHP - securityToken issue

我必须使用 PHP 语言实现一些处理 Microsoft Dynamics CRM 2015 的代码,并且由于我对 Dynamics CRM 和 Microsoft 服务完全陌生,所以这对我来说非常棘手,因为没有很好的文档对于非 .NET 语言。

我需要做的是创建 PHP API 读取和添加行到 Dynamic CRM 2015 的 "contacts" 和 "account" 表。

通过谷歌搜索,我发现身份验证部分的主要部分应该分四个主要步骤完成(摘自 Girish Raja 的博客):

1 - Pass in the device credentials and get a PUID. The device credentials is a randomly generated string that satisfies Live ID schema. You can generate one from this tool: Create CRM 2011 Beta Device
    POST login.live.com/ppsecure/DeviceAddCredential.srf
    Get the PUID from response   

2- Pass the device credentials
    POST login.live.com/liveidSTS.srf
    Get the device CiperData (BinaryDAToken)  

3- Pass the WLID username, password and device BinaryDAToken
    POST login.live.com/liveidSTS.srf
    Get the security tokens (2 CipherValues) & X509SubjectKeyIdentifier 

4- Do CRUD with the web service by passing X509SubjectKeyIdentifier, 2 CipherValues and the SOAP request (with data payload)
    POST yourorganization.api.crm.dynamics.com/XRMServices/2011/Organization.svc
    Get the result from the CRUD response and parse XML to get the data you need 

我顺利通过了第一点,从DeviceAddCredential.srf那里得到了一个puid,但是第二点好像没办法了。我一直收到 "The entered and stored passwords do not match"。

我实际上使用的是 Ben Speakman 的 dynamicsClient class,因为它是 2011 年 class,我的猜测是它的登录过程可能有问题(例如,我必须解决代码升级中的另一个问题 CURLOPT_SSLVERSION)。

这是尝试获取设备凭据的 getBinaryDAToken 函数。我不确定 url 正在使用 https://login.live.com/liveidSTS.srf。我的猜测是,也许 auth 服务从 login.live.com 转移了,我应该调用 office 365 产品的类似服务而不是 login.live.com。

其他一些脚本使用 login.microsoftonline.com/extSTS.srf 但看起来更旧 URL.

你能帮我完成这个授权程序吗? 非常感谢!

private function getBinaryDAToken(){

        $deviceCredentialsSoapTemplate = '
        <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:MessageID>
                    urn:uuid:'.$this->messageid.'
                </a:MessageID>
                <a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>
                <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPoy9Ez+P/wJdOhoN2XNauvYcAAAAAK0Y6fOjvMEqbgs9ivCmFPaZlxcAnCJ1GiX+Rpi09nSYACQAA</VsDebuggerCausalityData>
                <a:To s:mustUnderstand="1">https://login.live.com/liveidSTS.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">
                    <u:Timestamp u:Id="_0">
                        <u:Created>'.$this->currentTime.'Z</u:Created>
                        <u:Expires>'.$this->nextDayTime.'Z</u:Expires>
                    </u:Timestamp>
                    <o:UsernameToken u:Id="devicesoftware">
                        <o:Username>'.$this->deviceUserName.'</o:Username>
                        <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">
                            '.$this->devicePassword.'
                        </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>http://passport.net/tb</a:Address>
                        </a:EndpointReference>
                    </wsp:AppliesTo>
                    <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType>
                </t:RequestSecurityToken>
            </s:Body>
        </s:Envelope>';

        return $this->doCurl("/liveidSTS.srf" , "login.live.com" , "https://login.live.com/liveidSTS.srf", $deviceCredentialsSoapTemplate);



    }

更新:感谢 Campey 新登录 url https://login.microsoftonline.com/RST2.srf 解决了第二步问题

CRM Online 已从需要设备凭据的旧身份验证方法 (Windows Live) 发生变化,现在使用 Office 365 代替,这(在我看来)使事情变得更容易,而且速度肯定更快。

我写了一篇关于这个的博客:- http://crmtroubleshoot.blogspot.com.au/2013/07/dynamics-crm-2011-php-and-soap-using.html http://crmtroubleshoot.blogspot.com.au/2013/07/dynamics-crm-2011-php-and-soap-calls.html

Jason Lattimer 最近还写了一篇博客,它将提供一个您可以尝试实施的库,并且可以在本地使用(我的没有) http://jlattimer.blogspot.com.au/2015/02/soap-only-authentication-using-php.html