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();
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')
// token handling in session
var Credentials = require('./../../credentials');
// forge config information, such as client ID and secret
var config = require('./../../config');
// entity type encoder
var Encoder = require('node-html-encoder').Encoder;
var encoder = new Encoder('entity');
// web framework
var express = require('express');
var router = express.Router();
// OneDrive SDK
const msGraph = require("@microsoft/microsoft-graph-client").Client
function respondWithError(res, error) {
if (error.statusCode) {
res.status(error.statusCode).end(error.statusMessage)
} else {
res.status(500).end(error.message)
}
}
router.get('/api/storage/tree', function (req, res) {
var token = new Credentials(req.session);
var credentials = token.getStorageCredentials();
if (credentials === undefined) {
res.status(401).end();
return;
}
'use strict'; // http://www.w3schools.com/js/js_strict.asp
// token handling in session
var Credentials = require('./../../credentials');
// forge config information, such as client ID and secret
var config = require('./../../config');
// web framework
var express = require('express');
var router = express.Router();
var request = require('request');
// OneDrive SDK
const msGraph = require("@microsoft/microsoft-graph-client").Client;
var cryptiles = require('cryptiles');
// entity type encoder
var Encoder = require('node-html-encoder').Encoder;
var encoder = new Encoder('entity');
function respondWithError(res, error) {
if (error.statusCode) {
res.status(error.statusCode).end(error.statusMessage)
} else {
res.status(500).end(error.message)
}
}
router.get('/api/storage/signin', function (req, res) {
}, authHelper.getAccessToken(), (session, results, next) => {
if (results.response != null) {
var client = MicrosoftGraphClient.Client.init({
authProvider: (done) => {
done(null, results.response);
}
});
let searchQuery = `$search="${encodeURIComponent(this.term.entity)}"`;
var messages;
client
.api('me/messages')
.top(5)
.query(searchQuery)
.select('bodyPreview')
.get()
.then((res) => {
messages = res.value;
let text = [];
for (var i = 0; i < messages.length; i++) {
private init() {
this.client = graph.Client.init({
authProvider: (done) => {
if (this.dirConfig.applicationId == null || this.dirConfig.key == null ||
this.dirConfig.tenant == null) {
done(this.i18nService.t('dirConfigIncomplete'), null);
return;
}
if (!this.accessTokenIsExpired()) {
done(null, this.accessToken);
return;
}
this.accessToken = null;
this.accessTokenExpiration = null;
const data = querystring.stringify({