I want to sync my outlook 365 calendar events with my system. My system is a background service, not an application, therefore i can't provide a login screen for the user to approve authorization.
I'm following this link in order to get an access token
Get access without a user
I have called this link through the browser (pasted manually), in order to approve admin permissions, got an approval screen and approved admin permissions:
https://login.microsoftonline.com/mycompany.onmicrosoft.com/adminconsent?client_id=xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx&state=12345&redirect_uri=https%3A%2F%2Fmyserver.mycompany.com%2Fsugarcrmmaintest%2Fresponse.php
The response url was called as planned and I received a response.
Now I want to get the access token. I've been calling this code, according to the manual, but nothing happens and I don't get a response
$clientId = "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx";
$clientSecret = "mysecret";
$responseUri = "https%3A%2F%2Fmyserver.mycompany.com%2Fsugarcrmmaintest%2Fresponse.php";
$postUrl = "/mycomp.onmicrosoft.com/oauth2/v2.0/token";
$hostname = "login.microsoftonline.com";
$fullurl = "https://login.microsoftonline.com/mycompany.onmicrosoft.com/token";
$headers = array(
"POST " . $postUrl . " HTTP/1.1",
"Host: " . $hostname,
"Content-type: application/x-www-form-urlencoded",
);
$post_params = array(
"client_id" => $clientId,
"scope" => "https%3A%2F%2Fgraph.microsoft.com%2F.default",
"client_secret" => $clientSecret,
"grant_type" => "client_credentials",
);
$curl = curl_init($fullurl);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_params);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("application/x-www-form-urlencoded"));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
Did I forget something?
This is the explanation in the training page:
I have read tens of posts here, but all of them are examples that involve an authorization screen which I can't provide. I need the sync to work as a background service.