'"me request is only valid with delegated authentication flow" error when creating online meeting in teams using ms graph api
Got access token with given permission online meating read write delegated but getting this error
"/me request is only valid with delegated authentication flow."
i tried in postman https://graph.microsoft.com/v1.0/me/onlineMeetings with
{
"startDateTime":"2019-09-09T14:33:30.8546353-07:00",
"endDateTime":"2019-09-09T15:33:30.8546353-07:00",
"subject":"hey",
"participants":{
"organizer":{
"identity":{
"user":{
"id":""
}
}
}
}
}
Solution 1:[1]
I'm relatively sure that something with your api permissions or access token is wrong. I build an entire flow from creation over receive and delete a meeting:
I used the password flow only for the unit test to get an delegated token
For this tests, you need to add the below K/V in your env:
AZURE_TENANT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
AZURE_CLIENT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
AZURE_CLIENT_SECRET=Sup@r5ecurE!
[email protected]
AZURE_PASSWORD=Sup@r5ecurE!
class GraphMeetingTest extends TestCase
{
protected function getAccessToken()
{
$url = 'https://login.microsoftonline.com/' . env('AZURE_TENANT_ID') . '/oauth2/v2.0/token';
return Http::asForm()->post($url, [
'grant_type' => 'password',
'username' => env('AZURE_USER'),
'password' => env('AZURE_PASSWORD'),
'client_id' => env('AZURE_CLIENT_ID'),
'client_secret' => env('AZURE_CLIENT_SECRET'),
'scope' => 'openid profile offline_access .default',
]);
}
/** @test */
public function get_access_token()
{
$response = $this->getAccessToken();
$token = $response->json()['access_token'];
$this->assertEquals(200, $response->status());
$this->assertIsString($token);
return $token;
}
/** @test
* @depends get_access_token
*/
public function create_online_meeting($token)
{
$url = 'https://graph.microsoft.com/v1.0/me/onlineMeetings';
$startDateTime = Carbon::parse('08.05.2022 20:29', 'Europe/Berlin');
$endDateTime = Carbon::parse('08.05.2022 21:29', 'Europe/Berlin');
$subject = 'User Token Meeting';
$response = Http::withToken($token)->post($url, [
'startDateTime' => $startDateTime,
'endDateTime' => $endDateTime,
'subject' => $subject,
]);
$this->assertTrue($response->successful());
$this->assertArrayHasKey('id', $response->json());
return $response->json();
}
/** @test
* @depends create_online_meeting
*/
public function get_meeting_by_id($meeting)
{
$token = $this->getAccessToken()->json()['access_token'];
$url = 'https://graph.microsoft.com/v1.0/me/onlineMeetings/' . $meeting['id'];
$response = Http::withToken($token)->get($url);
$this->assertTrue($response->successful());
$this->assertArrayHasKey('id', $response->json());
return $response->json();
}
/** @test
* @depends get_meeting_by_id
*/
public function delete_online_meeting($meeting)
{
$token = $this->getAccessToken()->json()['access_token'];
$url = 'https://graph.microsoft.com/v1.0/me/onlineMeetings/' . $meeting['id'];
$response = Http::withToken($token)->delete($url);
$this->assertTrue($response->successful());
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | lordisp |
