How to use @microsoft/microsoft-graph-client - 10 common examples

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 Autodesk-Forge / bim360appstore-data.management-nodejs-transfer.storage / server / storages / onedrive / tree.js View on Github external
// 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
        }
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 jitsi / jitsi-meet / react / features / calendar-sync / web / microsoftCalendar.js View on Github external
return (dispatch: Dispatch, getState: Function): Promise&lt;*&gt; =&gt; {
            const state = getState()['features/calendar-sync'] || {};
            const token = state.msAuthState &amp;&amp; state.msAuthState.accessToken;

            if (!token) {
                return Promise.reject('Not authorized, please sign in!');
            }

            const client = Client.init({
                authProvider: done =&gt; done(null, token)
            });

            return client
                .api(MS_API_CONFIGURATION.CALENDAR_ENDPOINT)
                .get()
                .then(response =&gt; {
                    const calendarIds = response.value.map(en =&gt; en.id);
                    const getEventsPromises = calendarIds.map(id =&gt;
                        requestCalendarEvents(
                            client, id, fetchStartDays, fetchEndDays));

                    return Promise.all(getEventsPromises);
                })

                // get .value of every element from the array of results,
github jitsi / jitsi-meet / react / features / calendar-sync / web / microsoftCalendar.js View on Github external
.then(text =&gt; {
                    const client = Client.init({
                        authProvider: done =&gt; done(null, token)
                    });

                    return client
                        .api(`/me/events/${id}`)
                        .get()
                        .then(description =&gt; {
                            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
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 24.bot-authentication-msgraph / simple-graph-client.js View on Github external
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.
            }
        });
    }
github Autodesk-Forge / bim360appstore-data.management-nodejs-transfer.storage / server / storages / onedrive / integration.js View on Github external
utility.assertIsFolder(req.body.autodeskFolder, req, function (autodeskProjectId, autodeskFolderId) {
    //&lt;&lt;&lt;
    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

      // &gt;&gt;&gt;
      utility.prepareAutodeskStorage(autodeskProjectId, autodeskFolderId, fileName, req, function (autodeskStorageUrl, skip, callbackData) {
        if (skip) {
          res.status(409).end(); // no action (server-side)