How to use the @microsoft/microsoft-graph-client.Client function in @microsoft/microsoft-graph-client

To help you get started, we’ve selected a few @microsoft/microsoft-graph-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jasonjoh / node-tutorial / index.js View on Github external
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) =&gt; {
        // 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();
github jasonjoh / node-tutorial / routes / mail.js View on Github external
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);
github jasonjoh / node-tutorial / routes / contacts.js View on Github external
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;
github microsoft / VoTT / server / src / graph.ts View on Github external
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;
}
github jasonjoh / node-tutorial / routes / calendar.js View on Github external
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')
github Autodesk-Forge / bim360appstore-data.management-nodejs-transfer.storage / server / storages / onedrive / tree.js View on Github external
// 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;
  }
github Autodesk-Forge / bim360appstore-data.management-nodejs-transfer.storage / server / storages / onedrive / oauth.js View on Github external

'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) {
github microsoftgraph / nodejs-sentiment-bot-sample / src / server / dialogs / searchDialog.js View on Github external
}, authHelper.getAccessToken(), (session, results, next) =&gt; {
            if (results.response != null) {
                var client = MicrosoftGraphClient.Client.init({
                    authProvider: (done) =&gt; {
                        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) =&gt; {
                    messages = res.value;
                    let text = [];
                    for (var i = 0; i &lt; messages.length; i++) {
github bitwarden / directory-connector / src / services / azure-directory.service.ts View on Github external
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({