-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.php
124 lines (101 loc) · 3.99 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
include 'CrmAuth.php';
include 'CrmExecuteSoap.php';
include "CrmAuthenticationHeader.php";
// CRM Online
$url = "https://org.crm.dynamics.com/";
$username = "username@org.onmicrosoft.com";
$password = "password";
$crmAuth = new CrmAuth ();
$authHeader = $crmAuth->GetHeaderOnline ( $username, $password, $url );
// End CRM Online
// CRM On Premise - IFD
// $url = "https://org.domain.com/";
// //Username format could be domain\\username or username in the form of an email
// $username = "username";
// $password = "password";
// $crmAuth = new CrmAuth();
// $authHeader = $crmAuth->GetHeaderOnPremise($username, $password, $url);
// End CRM On Premise - IFD
$userid = WhoAmI ( $authHeader, $url );
if ($userid == null)
return;
$name = CrmGetUserName ( $authHeader, $userid, $url );
print $name;
function WhoAmI($authHeader, $url) {
$xml = "<s:Body>";
$xml .= "<Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\">";
$xml .= "<request i:type=\"c:WhoAmIRequest\" xmlns:b=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:c=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
$xml .= "<b:Parameters xmlns:d=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\"/>";
$xml .= "<b:RequestId i:nil=\"true\"/>";
$xml .= "<b:RequestName>WhoAmI</b: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 == "UserId") {
return $value->lastChild->textContent;
}
}
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;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252">
<title>CRM Auth PHP</title>
</head>
<body></body>
</html>