Reputation: 173
I have an access token, but I need to send it to verify myself via the graph API. How do I make a get request there ?
The API is :
https://graph.microsoft.com/beta/me/
I tried :
https://graph.microsoft.com/beta/me?access_token=
and
https://graph.microsoft.com/beta/me/access_token=
But neither works, it says it's empty.
Thanks in advance
Upvotes: 1
Views: 554
Reputation: 153
You need to add an Authorization header to the request containing the word Bearer and the authorization token:
Authorization: Bearer <access_token>
The token itself is a base64 encoded string.
This sample PHP application may help, Microsoft Graph OneNote API PHP Sample. Of particular interest here would be lines 280
-303
of submit.php
:
function initCurl($type = 'multipart')
{
$cookieValues = parseQueryString(@$_COOKIE['graph_auth']);
//Since cookies are user-supplied content, it must be encoded to avoid header injection
$encodedAccessToken = rawurlencode(@$cookieValues['access_token']);
$initUrl = $this->getPagesEndpointUrlWithSectionName();
$ch = curl_init($initUrl);
curl_setopt($ch, CURLOPT_HEADER, 1);
if ($type == 'multipart') {
curl_setopt($ch,CURLOPT_HTTPHEADER,array(
"Content-Type: multipart/form-data; boundary=$this->boundary\r\n".
"Authorization: Bearer ".$encodedAccessToken
));
}
else { //simple single-part request
curl_setopt($ch,CURLOPT_HTTPHEADER,array(
"Content-Type:text/html\r\n".
"Authorization: Bearer ".$encodedAccessToken
));
}
//configures curl_exec() to return the response as a string rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//use HTTP POST method
curl_setopt($ch,CURLOPT_POST,true);
return $ch;
}
Upvotes: 2