Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function contacts(response, request) {
const token = getValueFromCookie('node-tutorial-token', request.headers.cookie);
console.log('Token found in cookie: ', token);
if (token) {
response.writeHead(200, {'Content-Type': 'text/html'});
response.write('<div><h1>Your contacts</h1></div>');
// Create a Graph client
const client = microsoftGraph.Client.init({
authProvider: (done) => {
// Just return the token
done(null, token);
}
});
try {
// Get the first 10 contacts in alphabetical order
// by given name
const res = await client
.api('/me/contacts')
.top(10)
.select('givenName,surname,emailAddresses')
.orderby('givenName ASC')
.get();
// driveId:itemId
var idParts = id.split(':')
var driveId = idParts[0]
var id = idParts[1]
var path = ''
try {
if (driveId === '#') {
path = '/me/drives'
} else if (!id) {
path = '/me/drives/' + driveId + '/root/children'
} else {
path = '/me/drives/' + driveId + '/items/' + id + '/children'
}
var msGraphClient = msGraph.init({
defaultVersion: 'v1.0',
debugLogging: true,
authProvider: function (done) {
done(null, credentials.access_token)
}
})
msGraphClient
.api(path)
.get(function (error, data) {
if (error) {
console.log(error)
respondWithError(res, error)
return
}
router.get('/', async function(req, res, next) {
let parms = { title: 'Inbox', active: { inbox: true } };
const accessToken = await authHelper.getAccessToken(req.cookies, res);
const userName = req.cookies.graph_user_name;
if (accessToken && userName) {
parms.user = userName;
// Initialize Graph client
const client = graph.Client.init({
authProvider: (done) => {
done(null, accessToken);
}
});
try {
// Get the 10 newest messages from inbox
const result = await client
.api('/me/mailfolders/inbox/messages')
.top(10)
.select('subject,from,receivedDateTime,isRead')
.orderby('receivedDateTime DESC')
.get();
parms.messages = result.value;
res.render('mail', parms);
router.get('/', async function(req, res, next) {
let parms = { title: 'Contacts', active: { contacts: true } };
const accessToken = await authHelper.getAccessToken(req.cookies, res);
const userName = req.cookies.graph_user_name;
if (accessToken && userName) {
parms.user = userName;
// Initialize Graph client
const client = graph.Client.init({
authProvider: (done) => {
done(null, accessToken);
}
});
try {
// Get the first 10 contacts in alphabetical order
// by given name
const result = await client
.api('/me/contacts')
.top(10)
.select('givenName,surname,emailAddresses')
.orderby('givenName ASC')
.get();
parms.contacts = result.value;
export function client(access_token: string): graphClient.Client {
// Initialize Graph client
const result = graphClient.Client.init({
// Use the provided access token to authenticate
// requests
authProvider: (done: (err: any, access_token: string) => void) => {
done(null, access_token);
},
});
return result;
}
router.get('/', async function(req, res, next) {
let parms = { title: 'Calendar', active: { calendar: true } };
const accessToken = await authHelper.getAccessToken(req.cookies, res);
const userName = req.cookies.graph_user_name;
if (accessToken && userName) {
parms.user = userName;
// Initialize Graph client
const client = graph.Client.init({
authProvider: (done) => {
done(null, accessToken);
}
});
// Set start of the calendar view to today at midnight
const start = new Date(new Date().setHours(0,0,0));
// Set end of the calendar view to 7 days from start
const end = new Date(new Date(start).setDate(start.getDate() + 7));
try {
// Get the first 10 events for the coming week
const result = await client
.api(`/me/calendarView?startDateTime=${start.toISOString()}&endDateTime=${end.toISOString()}`)
.top(10)
.select('subject,start,end,attendees')
return (dispatch: Dispatch, getState: Function): Promise<*> => {
const state = getState()['features/calendar-sync'] || {};
const token = state.msAuthState && state.msAuthState.accessToken;
if (!token) {
return Promise.reject('Not authorized, please sign in!');
}
const client = Client.init({
authProvider: done => done(null, token)
});
return client
.api(MS_API_CONFIGURATION.CALENDAR_ENDPOINT)
.get()
.then(response => {
const calendarIds = response.value.map(en => en.id);
const getEventsPromises = calendarIds.map(id =>
requestCalendarEvents(
client, id, fetchStartDays, fetchEndDays));
return Promise.all(getEventsPromises);
})
// get .value of every element from the array of results,
.then(text => {
const client = Client.init({
authProvider: done => done(null, token)
});
return client
.api(`/me/events/${id}`)
.get()
.then(description => {
const body = description.body;
if (description.bodyPreview) {
body.content
= `${description.bodyPreview}<br><br>`;
}
// replace all new lines from the text with html
// <br> to make it pretty
constructor(token) {
if (!token || !token.trim()) {
throw new Error('SimpleGraphClient: Invalid token received.');
}
this._token = token;
// Get an Authenticated Microsoft Graph client using the token issued to the user.
this.graphClient = Client.init({
authProvider: (done) => {
done(null, this._token); // First parameter takes an error if you can't get an access token.
}
});
}
utility.assertIsFolder(req.body.autodeskFolder, req, function (autodeskProjectId, autodeskFolderId) {
//<<<
var storageId = req.body.storageItem;
var idParts = storageId.split(':')
var driveId = idParts[0]
storageId = idParts[1]
var path = '/drives/' + driveId + '/items/' + storageId
var msGraphClient = msGraph.init({
defaultVersion: 'v1.0',
debugLogging: true,
authProvider: function (done) {
done(null, token.getStorageCredentials().access_token)
}
})
msGraphClient
.api(path)
.get(function (err, fileInfo) {
var fileName = fileInfo.name; // name, that's all we need from Google
// >>>
utility.prepareAutodeskStorage(autodeskProjectId, autodeskFolderId, fileName, req, function (autodeskStorageUrl, skip, callbackData) {
if (skip) {
res.status(409).end(); // no action (server-side)