/** * Logs into Windows Live * * @return true on success else error */ public function login() { // Register device $register = $this->registerDevice(); // Get binary DA token $response = $this->getBinaryDAToken($this->messageid, $this->deviceUserName, $this->devicePassword); $responsedom = new DomDocument(); $responsedom->loadXML($response); $cipherValues = $responsedom->getElementsbyTagName("CipherValue"); $this->cipherValue = $cipherValues->item(0)->textContent; if (!empty($this->cipherValue)) { // Get security tokens $response = $this->getSecurityTokens($this->cipherValue); $responsedom = new DomDocument(); $responsedom->loadXML($response); $cipherValues = $responsedom->getElementsbyTagName("CipherValue"); $this->securityToken0 = $cipherValues->item(0)->textContent; $this->securityToken1 = $cipherValues->item(1)->textContent; $this->keyIdentifier = $responsedom->getElementsbyTagName("KeyIdentifier")->item(0)->textContent; if (empty($this->keyIdentifier) || empty($this->securityToken0) || empty($this->securityToken1)) { $this->_error = "Failed to get security tokens."; } else { return true; } } else { $this->_error = "Failed to get binary DA token."; } }
public function AuthenticateUser() { $SOAPresult = GetSOAPResponse('https://login.microsoftonline.com/RST2.srf', $this->BuildOCPSoap()); $responsedom = new DomDocument(); $responsedom->loadXML($SOAPresult); $cipherValues = $responsedom->getElementsbyTagName("CipherValue"); if (isset($cipherValues) && $cipherValues->length > 0) { $this->securityToken0 = $cipherValues->item(0)->textContent; $this->securityToken1 = $cipherValues->item(1)->textContent; $this->keyIdentifier = $responsedom->getElementsbyTagName("KeyIdentifier")->item(0)->textContent; } else { return null; } }
function CrmGetUserName($authHeader, $id, $url) { $xml = "<s:Body>"; $xml .= "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">"; $xml .= "<request i:type=\"a:RetrieveRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">"; $xml .= "<a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">"; $xml .= "<a:KeyValuePairOfstringanyType>"; $xml .= "<b:key>Target</b:key>"; $xml .= "<b:value i:type=\"a:EntityReference\">"; $xml .= "<a:Id>" . $id . "</a:Id>"; $xml .= "<a:LogicalName>systemuser</a:LogicalName>"; $xml .= "<a:Name i:nil=\"true\" />"; $xml .= "</b:value>"; $xml .= "</a:KeyValuePairOfstringanyType>"; $xml .= "<a:KeyValuePairOfstringanyType>"; $xml .= "<b:key>ColumnSet</b:key>"; $xml .= "<b:value i:type=\"a:ColumnSet\">"; $xml .= "<a:AllColumns>false</a:AllColumns>"; $xml .= "<a:Columns xmlns:c=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">"; $xml .= "<c:string>firstname</c:string>"; $xml .= "<c:string>lastname</c:string>"; $xml .= "</a:Columns>"; $xml .= "</b:value>"; $xml .= "</a:KeyValuePairOfstringanyType>"; $xml .= "</a:Parameters>"; $xml .= "<a:RequestId i:nil=\"true\" />"; $xml .= "<a:RequestName>Retrieve</a:RequestName>"; $xml .= "</request>"; $xml .= "</Execute>"; $xml .= "</s:Body>"; $executeSoap = new CrmExecuteSoap(); $response = $executeSoap->ExecuteSOAPRequest($authHeader, $xml, $url); $responsedom = new DomDocument(); $responsedom->loadXML($response); $firstname = ""; $lastname = ""; $values = $responsedom->getElementsbyTagName("KeyValuePairOfstringanyType"); foreach ($values as $value) { if ($value->firstChild->textContent == "firstname") { $firstname = $value->lastChild->textContent; } if ($value->firstChild->textContent == "lastname") { $lastname = $value->lastChild->textContent; } } return $firstname . " " . $lastname; }
function getAccount($authHeader, $url) { // $xml = "<s:Body>"; // $xml .= '<execute xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\">'; // $xml .= ' <request i:type=\"a:RetrieveAllEntitiesRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">'; // $xml .= ' <a:parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">'; // $xml .= ' <a:keyvaluepairofstringanytype>'; // $xml .= ' <b:key>EntityFilters</b:key>'; // $xml .= ' <b:value i:type=\"c:EntityFilters\" xmlns:c=\"http://schemas.microsoft.com/xrm/2011/Metadata\">Entity</b:value>'; // $xml .= ' </a:keyvaluepairofstringanytype>'; // $xml .= ' <a:keyvaluepairofstringanytype>'; // $xml .= ' <b:key>RetrieveAsIfPublished</b:key>'; // $xml .= ' <b:value i:type=\"c:boolean\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">true</b:value>'; // $xml .= ' </a:keyvaluepairofstringanytype>'; // $xml .= ' </a:parameters>'; // $xml .= ' <a:requestid i:nil=\"true\">'; // $xml .= ' <a:requestname>RetrieveAllEntities</a:requestname>'; // $xml .= ' </a:requestid></request>'; // $xml .= '</execute>'; // $xml .= "</s:Body>"; //este funciona $xml = '<s:Body>'; $xml .= ' <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">'; $xml .= ' <request i:type="a:RetrieveMultipleRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">'; $xml .= ' <a:Parameters xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">'; $xml .= ' <a:KeyValuePairOfstringanyType>'; $xml .= ' <b:key>Query</b:key>'; $xml .= ' <b:value i:type="a:QueryExpression">'; $xml .= ' <a:ColumnSet>'; $xml .= ' <a:AllColumns>false</a:AllColumns>'; $xml .= ' <a:Columns xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays">'; $xml .= ' <c:string>firstname</c:string>'; $xml .= ' <c:string>lastname</c:string>'; $xml .= ' </a:Columns>'; $xml .= ' </a:ColumnSet>'; $xml .= ' <a:Criteria>'; $xml .= ' <a:Conditions>'; $xml .= ' <a:ConditionExpression>'; $xml .= ' <a:AttributeName>emailaddress1</a:AttributeName>'; $xml .= ' <a:Operator>Equal</a:Operator>'; $xml .= ' <a:Values xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/Arrays">'; $xml .= ' <c:anyType i:type="d:string" xmlns:d="http://www.w3.org/2001/XMLSchema">someone_a@example.com</c:anyType>'; $xml .= ' </a:Values>'; $xml .= ' </a:ConditionExpression>'; $xml .= ' </a:Conditions>'; $xml .= ' <a:FilterOperator>And</a:FilterOperator>'; $xml .= ' <a:Filters />'; $xml .= ' <a:IsQuickFindFilter>false</a:IsQuickFindFilter>'; $xml .= ' </a:Criteria>'; $xml .= ' <a:Distinct>false</a:Distinct>'; $xml .= ' <a:EntityName>contact</a:EntityName>'; $xml .= ' <a:LinkEntities />'; $xml .= ' <a:Orders />'; $xml .= ' <a:PageInfo>'; $xml .= ' <a:Count>0</a:Count>'; $xml .= ' <a:PageNumber>0</a:PageNumber>'; $xml .= ' <a:PagingCookie i:nil="true" />'; $xml .= ' <a:ReturnTotalRecordCount>false</a:ReturnTotalRecordCount>'; $xml .= ' </a:PageInfo>'; $xml .= ' <a:NoLock>false</a:NoLock>'; $xml .= ' </b:value>'; $xml .= ' </a:KeyValuePairOfstringanyType>'; $xml .= ' </a:Parameters>'; $xml .= ' <a:RequestId i:nil="true" />'; $xml .= ' <a:RequestName>RetrieveMultiple</a:RequestName>'; $xml .= ' </request>'; $xml .= ' </Execute>'; $xml .= ' </s:Body>'; // $xml = '<s:Body>'; // $xml .= ' <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">'; // $xml .= ' <request i:type=\"a:RetrieveMultipleRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">'; // $xml .= ' <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">'; // $xml .= ' <a:KeyValuePairOfstringanyType>'; // $xml .= ' <b:key>Target</b:key>'; // $xml .= ' <b:value i:type=\"a:EntityReference\">'; // $xml .= "<a:Name i:nil=\"true\" />"; // $xml .= ' </b:value>'; // $xml .= ' </a:KeyValuePairOfstringanyType>'; // $xml .= "<a:KeyValuePairOfstringanyType>"; // $xml .= "<b:key>ColumnSet</b:key>"; // $xml .= "<b:value i:type=\"a:ColumnSet\">"; // $xml .= ' <a:AllColumns>false</a:AllColumns>'; // $xml .= ' <a:Columns xmlns:c=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">'; // $xml .= ' <c:string>firstname</c:string>'; // $xml .= ' </a:Columns>'; // $xml .= ' </a:ColumnSet>'; // $xml .= ' <a:EntityName>contact</a:EntityName>'; // $xml .= "</b:value>"; // $xml .= "</a:KeyValuePairOfstringanyType>"; // $xml .= ' </a:Parameters>'; // $xml .= ' <a:RequestId i:nil="true" />'; // $xml .= ' <a:RequestName>RetrieveMultiple</a:RequestName>'; // $xml .= ' </request>'; // $xml .= ' </Execute>'; // $xml .= ' </s:Body>'; // $xml = "<s:Body>"; // $xml .= "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">"; // $xml .= "<request i:type=\"a:RetrieveRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">"; // $xml .= "<a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">"; // $xml .= "<a:KeyValuePairOfstringanyType>"; // $xml .= "<b:key>Target</b:key>"; // $xml .= "<b:value i:type=\"a:EntityReference\">"; // $xml .= "<a:Id>" . $id . "</a:Id>"; // $xml .= "<a:LogicalName>systemuser</a:LogicalName>"; // $xml .= "<a:Name i:nil=\"true\" />"; // $xml .= "</b:value>"; // $xml .= "</a:KeyValuePairOfstringanyType>"; // $xml .= "<a:KeyValuePairOfstringanyType>"; // $xml .= "<b:key>ColumnSet</b:key>"; // $xml .= "<b:value i:type=\"a:ColumnSet\">"; // $xml .= "<a:AllColumns>false</a:AllColumns>"; // $xml .= "<a:Columns xmlns:c=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">"; // $xml .= "<c:string>firstname</c:string>"; // $xml .= "<c:string>lastname</c:string>"; // $xml .= "</a:Columns>"; // $xml .= "</b:value>"; // $xml .= "</a:KeyValuePairOfstringanyType>"; // $xml .= "</a:Parameters>"; // $xml .= "<a:RequestId i:nil=\"true\" />"; // $xml .= "<a:RequestName>Retrieve</a:RequestName>"; // $xml .= "</request>"; // $xml .= "</Execute>"; // $xml .= "</s:Body>"; $executeSoap = new CrmExecuteSoap(); $response = $executeSoap->ExecuteSOAPRequest($authHeader, $xml, $url); $responsedom = new DomDocument(); $responsedom->loadXML($response); $values = $responsedom->getElementsbyTagName("KeyValuePairOfstringanyType"); foreach ($values as $value) { if ($value->firstChild->textContent == "firstname") { $firstname = $value->lastChild->textContent; } if ($value->firstChild->textContent == "lastname") { $lastname = $value->lastChild->textContent; } } return $firstname . " " . $lastname; }
public function readOrg($accountId, $CRMURL, $securityData) { $domainname = substr($CRMURL, 8, -1); $pos = strpos($domainname, "/"); $domainname = substr($domainname, 0, $pos); $accountsRequest = EntityUtils::getCRMSoapHeader($CRMURL, $securityData) . ' <s:Body> <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services"> <request i:type="b:RetrieveMultipleRequest" xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <b:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"> <b:KeyValuePairOfstringanyType> <c:key>Query</c:key> <c:value i:type="b:FetchExpression"> <b:Query><fetch mapping="logical" count="50" version="1.0">
 <entity name="account">
 <attribute name="name" />
 <attribute name="address1_city" />
 <attribute name="telephone1" />
 <filter type="and"> <condition attribute="accountid" operator="eq" value="' . $accountId . '" /> </filter> </entity>
 </fetch> </b:Query> </c:value> </b:KeyValuePairOfstringanyType> </b:Parameters> <b:RequestId i:nil="true"/><b:RequestName>RetrieveMultiple</b:RequestName> </request> </Execute> </s:Body> </s:Envelope> '; $response = LiveIDManager::GetSOAPResponse("/Organization.svc", $domainname, $CRMURL, $accountsRequest); $accountsArray = array(); if ($response != null && $response != "") { $responsedom = new DomDocument(); $responsedom->loadXML($response); $entities = $responsedom->getElementsbyTagName("Entity"); foreach ($entities as $entity) { $account = array(); $kvptypes = $entity->getElementsbyTagName("KeyValuePairOfstringanyType"); foreach ($kvptypes as $kvp) { $key = $kvp->getElementsbyTagName("key")->item(0)->textContent; $value = $kvp->getElementsbyTagName("value")->item(0)->textContent; if ($key == 'accountid') { $account['accountId'] = $value; } if ($key == 'name') { $account['name'] = $value; } if ($key == 'telephone1') { $account['telephone'] = $value; } if ($key == 'address1_city') { $account['address'] = $value; } } $accountsArray[] = $account; } } return $accountsArray; }
/** * Gets the name of the AD FS server CRM uses for authentication. * * @return String The AD FS server url. * @param String $url * The Url of the CRM On Premise (IFD) organization (https://org.domain.com). */ function GetADFS($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url . "XrmServices/2011/Organization.svc?wsdl=wsdl0"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); curl_close($ch); $responsedom = new DomDocument(); $responsedom->loadXML($response); $identifiers = $responsedom->getElementsbyTagName("Identifier"); $identifier = $identifiers->item(0)->textContent; return str_replace("http://", "https://", $identifier); }
/** * Writes data into an GPX-file. * @param $bAppend * true: appends data into existing file * false: creates a new file * @param $aFile * the name of the xml-file * @param $aLatitude * a latitude-value * @param $aLongitude * a longitude-value * @param $aSpeed * a speed-value * @param $anAltitude * an altitude-value * @param $aDirection * a direction-value */ function writeGPXfile($bAppend, $aFile, $csvLines) { $doc = new DomDocument("1.0", "UTF-8"); if (!$doc) { echo "error creating dom document"; return false; } if ($bAppend == true) { // we want to append to existing data in a file // check before, if it exists! if (file_exists($aFile)) { $doc->load($aFile); } } // make the XML-file human-readable $doc->preserveWhiteSpace = false; $doc->formatOutput = true; // check, if we got a root element if (!$doc->documentElement) { $root = $doc->createElement("gpx"); if (!$root) { echo "error fetching root"; return false; } $doc->appendChild($root); } else { $root = $doc->documentElement; } // adding some attributes for the root $root->setAttribute('xmlns', "http://www.topografix.com/GPX/1/1"); $root->setAttribute('creator', "geo5"); $root->setAttribute('version', "1.1"); $root->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance"); $root->setAttribute('xsi:schemaLocation', "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"); $myTempTime = getdate(); $myMonth = $myTempTime['mon']; if ($myMonth < 10) { $myMonth = "0" . $myMonth; } $myDays = $myTempTime['mday']; if ($myDays < 10) { $myDays = "0" . $myDays; } $myHours = $myTempTime['hours']; if ($myHours < 10) { $myHours = "0" . $myHours; } $myMinutes = $myTempTime['minutes']; if ($myMinutes < 10) { $myMinutes = "0" . $myMinutes; } $mySeconds = $myTempTime['seconds']; if ($mySeconds < 10) { $mySeconds = "0" . $mySeconds; } $myTime = $myTempTime['year'] . "-" . $myMonth . "-" . $myDays . "T" . $myHours . ":" . $myMinutes . ":" . $mySeconds . ".000Z+1:00"; // create trk-element, if not already there $trksegelement = $doc->getElementsbyTagName('trkseg')->item(0); if (!$trksegelement) { $trkelement = $doc->createElement('trk'); $root->appendChild($trkelement); $trksubElement = $doc->createElement('name', 'geo5-' . substr($myTime, 0, 10)); $trkelement->appendChild($trksubElement); // create a trkseg-element $trksegelement = $doc->createElement('trkseg'); $trkelement->appendChild($trksegelement); } if ($csvLines != '') { $lines = explode(PHP_EOL, $csvLines); $count = count($lines); for ($i = 0; $i < $count; $i++) { $line = $lines[$i]; // now create a new track-point in between the track-segment $element = $doc->createElement("trkpt"); if (!$element) { logMessage("error creating element"); } $searchString = '/lat=(.*?);/i'; if (preg_match($searchString, $line, $matches)) { $element->setAttribute('lat', $matches[1]); } else { logMessage("Did not find 'lat' while writing gpx for csv line {$line}."); return false; } $searchString = '/lon=(.*?);/i'; if (preg_match($searchString, $line, $matches)) { $element->setAttribute('lon', $matches[1]); } else { logMessage("Did not find 'lon' while writing gpx for csv line {$line}."); return false; } $trksegelement->appendChild($element); $searchString = '/altitude=(.*?);/i'; if (preg_match($searchString, $line, $matches)) { $subElement = $doc->createElement('ele', $matches[1]); $element->appendChild($subElement); } $searchString = '/time=(.*)/i'; if (preg_match($searchString, $line, $matches)) { $subElement = $doc->createElement('time', $matches[1]); $element->appendChild($subElement); } } // save it if ($doc->save($aFile) !== false) { logMessage("Wrote gpx file {$aFile}"); } else { logMessage("Failed to write gpx file {$aFile}"); return false; } return true; } }
public function authenticateWithLiveID($CRMUrl, $liveIDUsername, $liveIDPassword) { $deviceCredentials = DeviceIdManager::RegisterDevice(); // Register Device Credentials and get binaryDAToken $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:%s</a:MessageID> <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"> <u:Timestamp u:Id="_0"> <u:Created>%sZ</u:Created> <u:Expires>%sZ</u:Expires> </u:Timestamp> <o:UsernameToken u:Id="devicesoftware"> <o:Username>%s</o:Username> <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">%s</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>'; $soapTemplate = sprintf($deviceCredentialsSoapTemplate, LiveIDManager::gen_uuid(), LiveIDManager::getCurrentTime(), LiveIDManager::getNextDayTime(), $deviceCredentials->getDeviceName(), $deviceCredentials->getPassword()); $binaryDATokenXML = LiveIDManager::GetSOAPResponse("/liveidSTS.srf", "login.live.com", "https://login.live.com/liveidSTS.srf", $soapTemplate); preg_match('/<CipherValue>(.*)<\\/CipherValue>/', $binaryDATokenXML, $matches); $cipherValue = $matches[1]; // Step 3: Get Security Token by sending WLID username, password and device binaryDAToken $securityTokenSoapTemplate = '<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:%s</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"> uIDPozBEz+P/wJdOhoN2XNauvYcAAAAAK0Y6fOjvMEqbgs9ivCmFPaZlxcAnCJ1GiX+Rpi09nSYACQAA</VsDebuggerCausalityData> <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"> <u:Timestamp u:Id="_0"> <u:Created>%s</u:Created> <u:Expires>%s</u:Expires> </u:Timestamp> <o:UsernameToken u:Id="user"> <o:Username>%s</o:Username> <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">%s</o:Password> </o:UsernameToken> <wsse:BinarySecurityToken ValueType="urn:liveid:device" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <EncryptedData Id="BinaryDAToken0" Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#"> <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc"> </EncryptionMethod> <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> <ds:KeyName>http://Passport.NET/STS</ds:KeyName> </ds:KeyInfo> <CipherData> <CipherValue> %s" </CipherValue> </CipherData> </EncryptedData> </wsse:BinarySecurityToken> </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>%s</a:Address> </a:EndpointReference> </wsp:AppliesTo> <wsp:PolicyReference URI="MBI_FED_SSL" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" /> <t:RequestType>http://schemas.xmlsoap.org/ws/2005/02/trust/Issue</t:RequestType> </t:RequestSecurityToken> </s:Body> </s:Envelope>'; // Create the URN address of the format urn:crm:dynamics.com. // Replace crm with crm4 for Europe & crm5 for Asia. $URNAddress = "urn:crmemea:dynamics.com"; if (strpos($CRMUrl, "crm4.dynamics.com")) { $URNAddress = "urn:crmemea:dynamics.com"; } if (strpos($CRMUrl, "crm5.dynamics.com")) { $URNAddress = "urn:crmapac:dynamics.com"; } $securityTemplate = sprintf($securityTokenSoapTemplate, LiveIDManager::gen_uuid(), LiveIDManager::getCurrentTime(), LiveIDManager::getNextDayTime(), $liveIDUsername, $liveIDPassword, $cipherValue, $URNAddress); $securityTokenXML = LiveIDManager::GetSOAPResponse("/extSTS.srf", "login.microsoftonline.com", "https://login.microsoftonline.com/extSTS.srf", $securityTemplate); $responsedom = new DomDocument(); $responsedom->loadXML($securityTokenXML); $cipherValues = $responsedom->getElementsbyTagName("CipherValue"); if (isset($cipherValues) && $cipherValues->length > 0) { $securityToken0 = $cipherValues->item(0)->textContent; $securityToken1 = $cipherValues->item(1)->textContent; $keyIdentifier = $responsedom->getElementsbyTagName("KeyIdentifier")->item(0)->textContent; } else { return null; } $newSecurityData = new SecurityData($keyIdentifier, $securityToken0, $securityToken1); return $newSecurityData; }