I'm trying to get my calendar events out of MS Graph. I'm looking to get all the events for the day and update on regular intervals to reflect changes to the calendar.
I've been trying to use MSAL and the associated libraries for Graph in .net core but that's been going about as well as what I've got going in this post from Postman so I thought it might be worthwhile now to break it down to the simplest implementation I can think of and work from there.
var form = new FormData();
form.append("grant_type", "client_credentials");
form.append("client_id", "redacted");
form.append("client_secret", "redacted");
var settings = {
"url": "https://login.microsoftonline.com/<tenant_id>/oauth2/token",
"method": "GET",
"timeout": 0,
"headers": {
"Content-Type": "application/x-www-form-urlencoded",
"Cookie": "fpc=Ah_P6jijvE5KmU4A_TsujaRPsQKSAQAAAGdFSdgOAAAA; stsservicecookie=estsfd; x-ms-gateway-slice=estsfd"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});
The token generates fine but when I try to use it to query MS Graph, it fails saying Access token validation failure. Invalid audience.
var settings = {
"url": "https://graph.microsoft.com/v1.0/me/events",
"method": "GET",
"timeout": 0,
"headers": {
"Authorization": "Bearer my_token_string_goes_here"
},
};
$.ajax(settings).done(function (response) {
console.log(response);
});
As far as I can figure this token should work but I'm at a loss. I thought it wasn't the correct endpoint to be getting a token for Graph from but that doesn't seem to be the issue.
Can anyone assist?
Thanks in advance!