Non sono ancora riuscito a trovare una soluzione.
ho cambiato un pò sistema sperando in meglio.
Codice PHP:
$authUrl = 'https://login.microsoftonline.com/id/oauth2/authorize';
$data = array( 'client_id' => ('id'), 'client_secret' => ('secret'), 'response_type' => 'code', 'redirect_uri' => 'https://ser-dev.biblico.it/MS_login/login', 'scope' => 'https://graph.microsoft.com/.default', 'grant_type' => 'client_credentials', 'resource'=>"https%3A%2F%2Fmanagement.azure.com%2F", 'state'=>"12345" //'response_mode'=>'form_post' ); redirect($authUrl . '?' . http_build_query($data));
poi
Codice PHP:
$auth = $_GET['code']; $resource_id = "api://fid-applicazione/Login"; $data = "client_id=".$client_id."&redirect_uri=".urlencode($redirect_uri)."&client_secret=".urlencode($client_secret)."&code=".$auth."&grant_type=authorization_code&resource=".$resource_id;
try {
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://login.microsoftonline.com/id/oauth2/v2.0/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/x-www-form-urlencoded', ));
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch); } catch (Exception $exception) { var_dump($exception);
}var_dump($output);
$out2 = json_decode($output, true);
$get_access_token = $out2['access_token'];
$get_refresh_token = $out2['refresh_token'];
$arraytoreturn = Array( 'access_token' => $out2['access_token'], 'refresh_token' => $out2['refresh_token'], 'expires_in' => $out2['expires_in'] );
echo "Get access toke and refresh token in office 365 using PHP<br>"; echo "access token :: ".$get_access_token."<br>"; echo "refresh token :: ".$get_refresh_token."<br>"; }