NodeJs Приложение для создания пользователей через MS Graph - PullRequest
0 голосов
/ 08 января 2020

Я разрабатываю приложение через node.js, чтобы создать пользователя в O365 с помощью MS Graph. Мне удалось получить токен в переменной, но я застрял, чтобы инициировать вызов POST для создания пользователя. Любая помощь здесь приветствуется. Ниже мой код:

const APP_ID = '';
const APP_SECERET = '';
const TOKEN_ENDPOINT ='https://login.microsoftonline.com/[domain].onmicrosoft.com/oauth2/v2.0/token';
const MS_GRAPH_SCOPE = 'https://graph.microsoft.com/.default';
const uri = 'https://graph.microsoft.com/v1.0/users';

const axios = require('axios');
const qs = require('qs');

const postData = {
  client_id: APP_ID,
  scope: MS_GRAPH_SCOPE,
  client_secret: APP_SECERET,
  grant_type: 'client_credentials'
};
const newuser= {
  accountEnabled: 'true',
  userPrincipalName: 'testuser5@[].onmicrosoft.com',
  displayName: 'Test user 5',
  passwordProfile: {
    password: 'Mypassword1!',
    forceChangePasswordNextSignIn: 'true'
  },
  'mailNickname': 'testuser5'
}
axios.defaults.headers.post['Content-Type'] =
  'application/x-www-form-urlencoded';

let token = '';

  axios
    .post(TOKEN_ENDPOINT, qs.stringify(postData))
    .then(response => {
      a = (response.data['access_token']);
      //console.log(a);
    app(a);

    })

    .catch(error => {
      console.log(error);
    });

//I NEED HELP HERE TO CALL POST REQUEST//

function app (b){
  axios
  .post(uri,b,qs.stringify(newuser))
  .then(Response =>{console.log(Response.data)}  

)
    .catch(error => {
      console.log(error);
    });
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...