首页 \ 问答 \ 使用Microsoft Office 365 API在租户中创建用户并将其链接到chrome Id(Creating users in tenant using Microsoft Office 365 API and link it to chrome Id)

使用Microsoft Office 365 API在租户中创建用户并将其链接到chrome Id(Creating users in tenant using Microsoft Office 365 API and link it to chrome Id)

我在我的项目的Azure活动目录中手动创建了一个用户,我能够获得用户。 我做了一个chrome扩展,GCM为我提供了一个我希望与微软账户链接的ID。

因此,对于每个用户,我希望GCM ID(获得此部分)和Azure AD ID链接在一起。

我正在做以下事情:

router.route('/users')
// create a user accessed at POST http://localhost:8080/api/users)
.post(function(req, res) {
  // Get an access token for the app.
  auth.getAccessToken().then(function (token) {
    console.log(token)
    var user = new User({
      officeId: token,
      name : req.body.name,
      email :req.body.email,
      chromeId : req.body.chromeId
    });
  user.save(function(err) {
      if (err)
          res.send(err);
      res.json({ message: 'User created!' });
  });
  });

});

但是,它的作用是获取身份验证令牌ID,chromeId,名称和电子邮件,然后将其添加到我的mongoose数据库中。

为了得到我想要达到的目标,我能做些什么? 我的队友说我正在做的是正确的,但我检查了Azure AD,我没有看到我的用户在那里授权。

顺便说一句,在前端,我要求用户提供他们的微软电子邮件和名称。

此外,我将我的代码与此处的代码合并https://github.com/OfficeDev/O365-Nodejs-Microsoft-Graph-App-only

 // @name getAccessToken
// @desc Makes a request for a token using client credentials.
auth.getAccessToken = function () {
  var deferred = Q.defer();

  // These are the parameters necessary for the OAuth 2.0 Client Credentials Grant Flow.
  // For more information, see Service to Service Calls Using Client Credentials (https://msdn.microsoft.com/library/azure/dn645543.aspx).
  var requestParams = {
    'grant_type': 'client_credentials',
    'client_id': config.clientId,
    'client_secret': config.clientSecret,
    'resource': 'https://graph.microsoft.com'
  };

  // Make a request to the token issuing endpoint.
  request.post({url: config.tokenEndpoint, form: requestParams}, function (err, response, body) {
    var parsedBody = JSON.parse(body);

    if (err) {
      deferred.reject(err);
    } else if (parsedBody.error) {
      deferred.reject(parsedBody.error_description);
    } else {
      // If successful, return the access token.
      deferred.resolve(parsedBody.access_token);
    }
  });

  return deferred.promise;
};

I manually created a user in Azure active directory for my project and I am able to get the users. I made a chrome extension and GCM provides me a ID which I want to be linked with the microsoft account.

So for each user, I want a GCM id (got this part) and an Azure AD Id linked together.

I was doing the following:

router.route('/users')
// create a user accessed at POST http://localhost:8080/api/users)
.post(function(req, res) {
  // Get an access token for the app.
  auth.getAccessToken().then(function (token) {
    console.log(token)
    var user = new User({
      officeId: token,
      name : req.body.name,
      email :req.body.email,
      chromeId : req.body.chromeId
    });
  user.save(function(err) {
      if (err)
          res.send(err);
      res.json({ message: 'User created!' });
  });
  });

});

However, what this does is take the auth token id, chromeId, name and email and just adds it to my mongoose database.

What can I do differently in order to get what I want to achieve? My teammate says what I am doing is correct but I checked the Azure AD and I don't see my user authorized there.

Btw, in the front-end, I ask a user to give their microsoft email and name.

Also, I merged my code with the code found here https://github.com/OfficeDev/O365-Nodejs-Microsoft-Graph-App-only

 // @name getAccessToken
// @desc Makes a request for a token using client credentials.
auth.getAccessToken = function () {
  var deferred = Q.defer();

  // These are the parameters necessary for the OAuth 2.0 Client Credentials Grant Flow.
  // For more information, see Service to Service Calls Using Client Credentials (https://msdn.microsoft.com/library/azure/dn645543.aspx).
  var requestParams = {
    'grant_type': 'client_credentials',
    'client_id': config.clientId,
    'client_secret': config.clientSecret,
    'resource': 'https://graph.microsoft.com'
  };

  // Make a request to the token issuing endpoint.
  request.post({url: config.tokenEndpoint, form: requestParams}, function (err, response, body) {
    var parsedBody = JSON.parse(body);

    if (err) {
      deferred.reject(err);
    } else if (parsedBody.error) {
      deferred.reject(parsedBody.error_description);
    } else {
      // If successful, return the access token.
      deferred.resolve(parsedBody.access_token);
    }
  });

  return deferred.promise;
};

原文:https://stackoverflow.com/questions/35471242
更新时间:2024-01-12 15:01

最满意答案

使用x,y对创建一个新列

df['xy'] = df.apply(lambda x: [x['x'], x['y']], axis=1)

groupby并聚合成一个列表列表

gb = df.groupby('type')
df2 = gb.aggregate({'xy': lambda x: list(x)})

这会产生:

df2  
    xy
type    
a   [[1, 2], [3, 4], [5, 6]]
b   [[1, 2], [3, 4]]
c   [[1, 2], [3, 4], [5, 6]]

请注意,要应用距离函数,您必须执行以下操作:

from scipy.spatial import distance
df2['distances'] = df2['xy'].apply(lambda x: distance.pdist(x, 'euclidean'))

df2

    xy                          distances
type        
a   [[1, 2], [3, 4], [5, 6]]    [2.82842712475, 5.65685424949, 2.82842712475]
b   [[1, 2], [3, 4]]            [2.82842712475]
c   [[1, 2], [3, 4], [5, 6]]    [2.82842712475, 5.65685424949, 2.82842712475]

create a new column with pairs x,y

df['xy'] = df.apply(lambda x: [x['x'], x['y']], axis=1)

groupby and aggregate into a list of lists

gb = df.groupby('type')
df2 = gb.aggregate({'xy': lambda x: list(x)})

this produces:

df2  
    xy
type    
a   [[1, 2], [3, 4], [5, 6]]
b   [[1, 2], [3, 4]]
c   [[1, 2], [3, 4], [5, 6]]

note that to apply your distance function you have to do:

from scipy.spatial import distance
df2['distances'] = df2['xy'].apply(lambda x: distance.pdist(x, 'euclidean'))

df2

    xy                          distances
type        
a   [[1, 2], [3, 4], [5, 6]]    [2.82842712475, 5.65685424949, 2.82842712475]
b   [[1, 2], [3, 4]]            [2.82842712475]
c   [[1, 2], [3, 4], [5, 6]]    [2.82842712475, 5.65685424949, 2.82842712475]

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)