Guest User

Untitled

a guest
Dec 9th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. https://login.microsoftonline.com/mytenant.co.uk/oauth2/v2.0/authorize/?client_id=aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaa&redirect_uri=https://mywebsite.com/login/authentication&response_type=code&scope=Contacts.Read&state=12345
  2.  
  3. $get_code = $_GET['code'];
  4.  
  5. $ch = curl_init();
  6. curl_setopt_array($ch, array(
  7. CURLOPT_URL => 'https://login.microsoftonline.com/common/oauth2/v2.0/token/',
  8. CURLOPT_RETURNTRANSFER => 1,
  9. CURLOPT_POST => 1,
  10. CURLOPT_POSTFIELDS => array(
  11. "client_id" => "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaa",
  12. "client_secret" => "qwertyuiopasdfghjkl",
  13. "code" => $get_code,
  14. "redirect_uri" => "https://mywebsite.com/login/authentication",
  15. "grant_type" => "authorization_code",
  16. "scope" => "Contacts.Read"
  17. )
  18. ));
  19. $result = curl_exec($ch);
  20. curl_close($ch);
  21.  
  22. $result = json_decode($result);
  23.  
  24. $resultAccessToken = "Bearer ".$result->access_token;
  25.  
  26. $ch2 = curl_init();
  27. curl_setopt_array($ch2, array(
  28. CURLOPT_URL => 'https://graph.microsoft.com/v1.0/me/contacts',
  29. CURLOPT_RETURNTRANSFER => 1,
  30. CURLOPT_HEADER => 1,
  31. CURLOPT_HTTPHEADER => array(
  32. "Authorization" => $resultAccessToken
  33. )
  34. ));
  35. $result2 = curl_exec($ch2);
  36. curl_close($ch2);
  37.  
  38. echo $result2;
Add Comment
Please, Sign In to add comment