0.0.3 • Published 4 years ago

microsoft-api-wrapper v0.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

Microsoft API Wrapper

A wrapper around requests made to Microsoft APIs that acts as a middleware using a provided refresh_token to get a valid access_token and add it to the authorization header before the APIs call is made.

Usage

const MicrosoftAPIWrapperClient = require('microsoft-api-wrapper');

let msWrapperClient = new MicrosoftAPIWrapperClient(
  process.env.REFRESH_TOKEN,
  process.env.CLIENT_ID,
  process.env.CLIENT_SECRET,
  process.env.REDIRECT_URI,
  'Group.ReadWrite.All profile openid email', /* example scope */

  /* optionally you can pass in a different grant type, it defaults to 'refresh_token' */
  'refresh_token'
)

let additionalHeaders = {}

/* Make a GET request */

let userInfoResponse = msWrapperClient.getWithValidToken(
  'https://graph.microsoft.com/v1.0/users/me',
  additionalHeaders, (err, res) => {

  if (err) {
      throw err;
  }

  return res;

});


/* Make a POST request */

let postData = {
  'teamsApp@odata.bind': `https://graph.microsoft.com/v1.0/appCatalogs/teamsApps/${process.env.APP_DEFINITION_ID}`
}
let appAddedToTeamResponse = msWrapper.postWithValidToken(
  `https://graph.microsoft.com/v1.0/teams/${process.env.TEAM_ID}/installedApps`,
  postData, additionalHeaders, (err, res) => {

  if (err) {
    throw err;
  }

  return res;

});


/* Get a fresh valid access token for custom requests use without the wrapper client */

let newAccessToken = msWrapperClient.getValidAccessToken((err, accessToken) => {

  if (err) {
      throw err;
  }

  return accesstoken;

});
0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago