问题
I decided to create app from old azure portal and set the app to multi tenant. I have set the OAuth 2.0 token endpoint (https://login.microsoftonline.com/common/oauth2/token) for token and OAuth 2.0 authorization endpoint (https://login.microsoftonline.com/common/oauth2/authorize) for authorization. here is my code for authorization: header('location:https://login.microsoftonline.com/common/oauth2/authorize?response_type=code&scope=openid%20profile&client_id=xxxxxxxxxxxxxxx&redirect_uri=http://localhost/xxxxxxx/contacts/connectOffice');
and this is my code for fetching token:
$data = array (
'code' => $code,
'client_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=',
'client_id' => 'xxxxxxxxxxxxxxxxxxxx',
'grant_type' => 'authorization_code',
'redirect_uri' => 'http://localhost/xxxxxx/contacts/connectOffice',
'scope' =>'offline_access Contacts.ReadWrite'
);
$url = 'https://login.microsoftonline.com/common/oauth2/token';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
This is the result I get from the token request:
Array ( [token_type] => Bearer [expires_in] => 3599 [ext_expires_in] => 0 [expires_on] => 1487828228 [access_token] => AQABAAAAAADRNYRQ3dhRSrm-4K-adpCJ2ghMrdr3JJCVtGDvxtmOEHcFyxxxxxxxxxxxxxxxxvU_o8Ob_GixKxnHPPCAA [refresh_token] => AQABAAAAAADRxxxxxxxxxxx0EwuR_igY5qiAA [id_token] => eyJ0eXAiOiJKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxFaxpRFq48A )
I am using this access token which I am using to send a GET request to access Microsoft graph api(https://graph.microsoft.com/v1.0/me) for getting user profile. This is my get request:
$url = 'https://graph.microsoft.com/v1.0/me';
$headers = array(
"Authorization: Bearer ".$access_token
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$response=curl_exec($ch);
I am getting this error :
Array ( [error] => Array ( [code] => InvalidAuthenticationToken [message] => CompactToken parsing failed with error code: -2147184105 [innerError] => Array ( [request-id] => 43eae80b-c3f0-4909-a71d-4e5d3d982579 [date] => 2017-02-22T15:09:25 )
Can anyone suggest where I might be going wrong ?
来源:https://stackoverflow.com/questions/42395473/unable-to-get-user-profile-info-from-microsoft-graph-api