getMicrosoftAccessToken
Opens a new window to get user access from Microsoft to a specific scope.
Note: For more details on how to utilize this function, see Microsoft API documentation.
Description
vcc.getMicrosoftAccessToken(json: object, scope: string, callback: Function): void
Parameters
json
Client ID for native application.
scope
Name of the requested scope.
callback
This function will be retrieved with the access_token.
Return values
none
Examples
Retrieve calendar events from Outlook
var json = {
installed: {
redirect_uris: ['https://login.microsoftonline.com/common/oauth2/nativeclient'],
client_id: 'f114555a-312c-****-****-************',
client_secret: 'E[w=oX$%)K******************************',
auth_uri: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
token_uri: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
}
};
vcc.getMicrosoftAccessToken(json, 'email profile', function(accessToken) {
var startDateTime = '2019-02-08T12:00:00.0000000';
var endDateTime = '2019-02-12T12:00:00.0000000';
var request = vcc.httpRequest();
request.open('GET',`https://graph.microsoft.com/v1.0/me/calendarView?startDateTime=${startDateTime}&endDateTime=${endDateTime}`);
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Authorization', 'Bearer '+accessToken);
request.onload = function() {
var calendarEvents = JSON.parse(request.responseText);
dump(calendarEvents);
};
request.send();
});
Create an Outlook calendar event
var json = {installed: {...}};
vcc.getMicrosoftAccessToken(json, 'email profile', function(accessToken) {
var request = vcc.httpRequest();
var postData = {
subject: vcc.getFieldValue('event_name') || 'Subject',
body: {
contentType: 'text',
content: vcc.getFieldValue('event_description') || 'content',
},
start: {
dateTime: "2019-02-27T00:00:00Z",
timeZone: "Europe/Budapest"
},
end: {
dateTime: "2019-02-27T23:00:00Z",
timeZone: "Europe/Budapest"
},
reminderMinutesBeforeStart: 99,
isReminderOn: true,
};
request.open('POST', 'https://graph.microsoft.com/v1.0/me/calendar/events');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Authorization', 'Bearer '+accessToken);
request.onload = function() {
var respone = JSON.parse(request.responseText);
dump(respone);
};
request.send(JSON.stringify(postData));
});
Comments
Can’t find what you need? Use the comment section below to connect with others, get answers from our experts, or share your ideas with us.
There are no comments yet.