66
77class GraphTestBase
88{
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 ;
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+ public $ graphClient ;
1817
1918 public function __construct ()
2019 {
21- $ this ->clientId = CLIENT_ID ;
22- $ this ->username = USERNAME ;
23- $ this ->password = PASSWORD ;
20+ $ this ->clientId = CLIENT_ID ;
21+ $ this ->username = USERNAME ;
22+ $ this ->password = PASSWORD ;
2423
2524 $ this ->getAuthenticatedClient ();
2625 }
2726
2827 public function getAuthenticatedClient ()
2928 {
30- if ($ this ->graphClient == null )
31- {
32- $ this ->graphClient = new Graph ();
33- $ this ->graphClient ->setAccessToken ($ this ->getAccessToken ());
34- }
29+ if ($ this ->graphClient == null )
30+ {
31+ $ this ->graphClient = new Graph ();
32+ $ this ->graphClient ->setAccessToken ($ this ->getAccessToken ());
33+ }
3534 }
3635
37- private function getAccessToken ()
36+ public function getAccessToken ()
3837 {
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 ;
38+ $ body = "grant_type= " .$ this ->grantType
39+ . "&resource= " .$ this ->resource
40+ . "&client_id= " .$ this ->clientId
41+ . "&username= " .$ this ->username
42+ . "&password= " .$ this ->password ;
43+ $ ch = curl_init ();
44+ curl_setopt ($ ch , CURLOPT_URL , $ this ->endpoint );
45+ curl_setopt ($ ch , CURLOPT_POST , 1 );
46+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
47+ curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ body );
48+ curl_setopt ($ ch , CURLOPT_FAILONERROR , 0 );
49+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , array ($ this ->contentType , 'Content-Length: ' . strlen ($ body )));
50+
51+ $ result = curl_exec ($ ch );
52+ $ token = json_decode ($ result , true )['access_token ' ];
53+ curl_close ($ ch );
54+
55+ return $ token ;
5756 }
58- }
57+
58+ }
0 commit comments