66
77class GraphTestBase
88{
9- private $ clientId ;
10- private $ clientSecret ;
11- private $ username ;
12- private $ password ;
13- private $ contentType = "application/x-www-form-urlencoded " ;
14- private $ grantType = "password " ;
15- private $ endpoint = "https://login.microsoftonline .com/common/oauth2/token " ;
16- private $ resource = " https%3A%2F%2Fgraph.microsoft.com%2F " ;
17- public $ graphClient ;
9+ private $ clientId ;
10+ private $ username ;
11+ private $ password ;
12+ private $ contentType = " application/x-www-form-urlencoded " ;
13+ private $ grantType = "password " ;
14+ private $ endpoint = "https://login.microsoftonline.com/common/oauth2/token " ;
15+ private $ resource = "https%3A%2F%2Fgraph.microsoft .com%2F " ;
16+ private $ accessToken ;
17+ public $ graphClient ;
1818
1919 public function __construct ()
2020 {
21- $ this ->clientId = CLIENT_ID ;
22- $ this ->clientSecret = CLIENT_SECRET ;
23- $ this ->username = USERNAME ;
24- $ this ->password = PASSWORD ;
21+ $ this ->clientId = CLIENT_ID ;
22+ $ this ->username = USERNAME ;
23+ $ this ->password = PASSWORD ;
2524
2625 $ this ->getAuthenticatedClient ();
2726 }
2827
2928 public function getAuthenticatedClient ()
3029 {
31- if ($ this ->graphClient == null )
32- {
33- $ this ->graphClient = new Graph ();
34- $ this ->graphClient ->setAccessToken ($ this ->getAccessToken ());
35- }
30+ if ($ this ->graphClient == null )
31+ {
32+ $ this ->graphClient = new Graph ();
33+ $ this ->graphClient ->setAccessToken ($ this ->getAccessToken ());
34+ }
3635 }
3736
38- public function getAccessToken ()
37+ private function getAccessToken ()
3938 {
40- $ body = "grant_type= " .$ this ->grantType
41- ."&resource= " .$ this ->resource
42- ."&client_id= " .$ this ->clientId
43- ."&client_secret= " .$ this ->clientSecret
44- ."&username= " .$ this ->username
45- ."&password= " .$ this ->password ;
46- $ ch = curl_init ();
47- curl_setopt ($ ch , CURLOPT_URL , $ this ->endpoint );
48- curl_setopt ($ ch , CURLOPT_POST , 1 );
49- curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
50- curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ body );
51- curl_setopt ($ ch , CURLOPT_FAILONERROR , 0 );
52- curl_setopt ($ ch , CURLOPT_HTTPHEADER , array ($ this ->contentType , 'Content-Length: ' . strlen ($ body )));
53-
54- $ result = curl_exec ($ ch );
55- $ token = json_decode ($ result , true )['access_token ' ];
56- curl_close ($ ch );
57-
58- return $ token ;
39+ $ body = "grant_type= " .$ this ->grantType .
40+ "&resource= " .$ this ->resource .
41+ "&client_id= " .$ this ->clientId .
42+ "&username= " .$ this ->username .
43+ "&password= " .$ this ->password ;
44+ $ ch = curl_init ();
45+ curl_setopt ($ ch , CURLOPT_URL , $ this ->endpoint );
46+ curl_setopt ($ ch , CURLOPT_POST , 1 );
47+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
48+ curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ body );
49+ curl_setopt ($ ch , CURLOPT_FAILONERROR , 0 );
50+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , array ($ this ->contentType , 'Content-Length: ' . strlen ($ body )));
51+
52+ $ result = curl_exec ($ ch );
53+ $ token = json_decode ($ result , true )['access_token ' ];
54+ curl_close ($ ch );
55+
56+ return $ token ;
5957 }
60-
61- }
58+ }
0 commit comments