访问 Microsoft Dynamics CRM 2016 REST WEB API
Access Microsoft Dynamics CRM 2016 REST WEB API
我需要访问 CRM odata REST API 以进行集成。我有一个用于从 CRM 同步数据的 php cron 作业。当我从浏览器点击 CRM WEB API https://internal.crm.org.com:5443/appname/api/data/v8.0/ 的端点时,我重定向到以下 link :
https://adfs.crm.org.com/adfs/ls/?wa=wsignin1.0&wtrealm=https://internal.crm.org.com:5443/&wctx=rm=1&id=4d65271b-682e-44bb-80ce-ed44b5370ed7&ru=%2forgTechnicalTraining%2fdefault.aspx&wct=2016-11-02T07:15:47Z&wauth=urn:federation:authentication:windows
并显示 window 以使用用户名和密码进行身份验证。
所以我的问题是如何通过资源服务器进行身份验证?
Microsoft 将我指向此页面
https://msdn.microsoft.com/library/mt622431.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
这个人解释了如何使用 oauth2 进行身份验证
http://www.powerobjects.com/2016/01/22/start-your-engines-getting-started-with-the-crm-2016-web-api/#collapse2
Microsoft 表示 dynamics 365 使用三种不同的安全模型(声明、活动目录和 auth2 身份验证)
我已使用 ws-trust 协议成功与 CRM web api 2016 集成。
This lib 为您完成繁重的工作并实现 ws-trust 协议消息。
使用受 ADFS 3.0 保护的 CRM 进行身份验证的步骤
1- 获取相同的安全令牌(需要在 adfs 服务器上配置用于主动身份验证的 ws-trust 端点)
2- 在 header 中包含每个 http 请求的令牌作为早期令牌
代码:
<?php
include_once dirname(dirname(__FILE__)) . '/http.php';
include_once dirname(dirname(__FILE__)) . '/wstrust.php';
// username/password of a user in the LDAP directory
// LDAP as configured in the PingFederate Username Token WS-Trust connection settings for Salesforce
$username = 'username';
$password = 'password';
// RST appliesTo
$appliesTo = 'crmservice/api/data/v8.0/';
//STS service
$IPSTS = 'org/adfs/services/trust/13/UsernameMixed';
// special token type (needs to be enabled in run.properties)
$tokenType = WSTRUST::TOKENTYPE_SAML20;
// call to IP-STS, authenticate with uname/pwd, retrieve RSTR with generated token
//get security token
$result = HTTP::doSOAP(
$IPSTS,
WSTRUST::getRSTHeader(
WSTRUST::getUserNameToken($username, $password),
WSTRUST::getTimestampHeader(), $IPSTS),
WSTRUST::getRST($tokenType, $appliesTo)
);
// parse the RSTR that is returned
list($dom, $xpath, $token, $proofKey) = WSTRUST::parseRSTR($result);
$xpath->registerNamespace('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
$token = $xpath->query('saml:EncryptedAssertion', $token);
$token = $token->item(0);
// now pass the encrypted assertion to the RP
$ts = WSTRUST::getTimestampHeader('_0');
$token = $dom->saveXML($token);
//include the token with the http header per request like this Authorization: Bearer $token
我需要访问 CRM odata REST API 以进行集成。我有一个用于从 CRM 同步数据的 php cron 作业。当我从浏览器点击 CRM WEB API https://internal.crm.org.com:5443/appname/api/data/v8.0/ 的端点时,我重定向到以下 link : https://adfs.crm.org.com/adfs/ls/?wa=wsignin1.0&wtrealm=https://internal.crm.org.com:5443/&wctx=rm=1&id=4d65271b-682e-44bb-80ce-ed44b5370ed7&ru=%2forgTechnicalTraining%2fdefault.aspx&wct=2016-11-02T07:15:47Z&wauth=urn:federation:authentication:windows 并显示 window 以使用用户名和密码进行身份验证。
所以我的问题是如何通过资源服务器进行身份验证? Microsoft 将我指向此页面 https://msdn.microsoft.com/library/mt622431.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1 这个人解释了如何使用 oauth2 进行身份验证 http://www.powerobjects.com/2016/01/22/start-your-engines-getting-started-with-the-crm-2016-web-api/#collapse2
Microsoft 表示 dynamics 365 使用三种不同的安全模型(声明、活动目录和 auth2 身份验证)
我已使用 ws-trust 协议成功与 CRM web api 2016 集成。
This lib 为您完成繁重的工作并实现 ws-trust 协议消息。 使用受 ADFS 3.0 保护的 CRM 进行身份验证的步骤 1- 获取相同的安全令牌(需要在 adfs 服务器上配置用于主动身份验证的 ws-trust 端点) 2- 在 header 中包含每个 http 请求的令牌作为早期令牌 代码:
<?php
include_once dirname(dirname(__FILE__)) . '/http.php';
include_once dirname(dirname(__FILE__)) . '/wstrust.php';
// username/password of a user in the LDAP directory
// LDAP as configured in the PingFederate Username Token WS-Trust connection settings for Salesforce
$username = 'username';
$password = 'password';
// RST appliesTo
$appliesTo = 'crmservice/api/data/v8.0/';
//STS service
$IPSTS = 'org/adfs/services/trust/13/UsernameMixed';
// special token type (needs to be enabled in run.properties)
$tokenType = WSTRUST::TOKENTYPE_SAML20;
// call to IP-STS, authenticate with uname/pwd, retrieve RSTR with generated token
//get security token
$result = HTTP::doSOAP(
$IPSTS,
WSTRUST::getRSTHeader(
WSTRUST::getUserNameToken($username, $password),
WSTRUST::getTimestampHeader(), $IPSTS),
WSTRUST::getRST($tokenType, $appliesTo)
);
// parse the RSTR that is returned
list($dom, $xpath, $token, $proofKey) = WSTRUST::parseRSTR($result);
$xpath->registerNamespace('saml', 'urn:oasis:names:tc:SAML:2.0:assertion');
$token = $xpath->query('saml:EncryptedAssertion', $token);
$token = $token->item(0);
// now pass the encrypted assertion to the RP
$ts = WSTRUST::getTimestampHeader('_0');
$token = $dom->saveXML($token);
//include the token with the http header per request like this Authorization: Bearer $token