使用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
最满意答案
使用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]
相关问答
更多-
如果我理解正确,那么您正在尝试重塑数据框而不是按摘要分组,在这种情况下,您可以使用set_index()和set_index() unstack() : df.set_index(["A_Bucket", "B_Bucket"]).unstack(level=0) # Value # A_Bucket 0.100 0.125 0.150 # B_Bucket # 60.0 NaN NaN 0.0 ...
-
.loc同时接受行和列选择器(与.ix/.iloc FYI一样)这也是在单次传递中完成的。 In [1]: df = DataFrame(np.random.rand(4,5), columns = list('abcde')) In [2]: df Out[2]: a b c d e 0 0.669701 0.780497 0.955690 0.451573 0.232194 1 0.952762 0.5 ...
-
使用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] ...
-
Pandas数组到列(Pandas array to columns)[2023-10-01]
我在列表理解中使用np.append pd.DataFrame([np.append(*row) for row in data], columns=list('ABCZ')) A B C Z 0 0 0 1 1 1 0 1 1 1 2 1 0 1 0 3 1 1 1 1 或者使用np.column_stack和zip更有效 pd.DataFrame(np.column_stack(list(zip(*data))), columns=list('ABCZ') ... -
pandas与所有数据帧列中的聚合统计信息分组(pandas grouped with aggregation stats across all dataframe columns)[2023-05-18]
您不必逐个调用grouped['B'] grouped['C'] ,只需传递整个groupby对象,pandas就会将聚合函数应用于所有列。 import pandas as pd test_dataframe = pd.DataFrame({ 'A' : ['aa', 'aa', 'ac', 'ac', 'ac', 'ad', 'ad', 'ad', 'ad'], 'B' : [5, 3, 2, 9, 2, 0, 9, 6, 3], 'C' : [3, 2, 0, 2, 3, 0 ... -
将object类型的pandas数据框列转换为numpy数组(Convert a pandas dataframe column of type object to a numpy array)[2022-05-07]
我已经找到了这个问题的答案。 这非常直截了当,我只是没有看到它开始。 这是我如何获得对象数据以及numpy数组(.values :)) train_img_array = np.array([]) train_id_array = np.array([]) train_lab_array = np.array([]) train_id_array = img_train['ID'].values train_lab_array = img_train['class'].values train_img_ar ... -
自crosstab与crosstab merge d1 = df.merge(df, on='Customer').query('Product_x != Product_y') pd.crosstab(d1.Product_x, d1.Product_y) Product_y A B C Product_x A 0 2 1 B 2 0 1 C 1 1 0 你可以看到这个答案 ,以更好地了解如何加速crosstab ...
-
考虑一个示例系列ser1 ser1 = pd.Series( 'abc def ghi'.split(), 'sample1 sample2 sample3'.split()) 在将字符串列为字符列表后应用pd.Series 。 ser1.apply(lambda x: pd.Series(list(x))) \ .rename(columns=lambda x: 'char{}'.format(x + 1)) char1 char2 char3 sample1 ...
-
您可以将numpy数组直接传递给DataFrame构造函数: In [11]: a = np.random.rand(3, 5) In [12]: a Out[12]: array([[ 0.46154984, 0.08813473, 0.57746049, 0.42924157, 0.34689139], [ 0.29731858, 0.83300176, 0.15884604, 0.44753895, 0.56840054], [ 0.02479636, ...
-
正确地使用IIUC然后你使用lambda : In [19]: df['merged'] = df.apply(lambda row: {row['Stage_Name']:row['Metrics']}, axis=1) df Out[19]: Block_Name Metrics Stage_Name merged 0 A [(P, P), (Q, Q)] P {'P': [('P', ...