[英]Office 365 Calendar API trigger call to app based on creating event
[英]Creating users in tenant using Microsoft Office 365 API and link it to chrome Id
我在Azure活動目錄中為我的項目手動創建了一個用戶,並且能夠獲取用戶。 我做了一個chrome擴展程序,GCM為我提供了一個我想與Microsoft帳戶關聯的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!' });
});
});
});
但是,此操作需要使用auth令牌ID,chromeId,名稱和電子郵件,並將其添加到我的貓鼬數據庫中。
為了獲得想要實現的目標,我可以做些什么? 我的隊友說我正在做的事是正確的,但是我檢查了Azure AD,但沒有看到我的用戶被授權。
順便說一句,在前端,我請用戶提供他們的Microsoft電子郵件和名稱。
另外,我將代碼與此處找到的代碼合並在一起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;
};
如果要在AAD中創建用途,則可以利用Microsoft Graph API: Create User
,該代碼未在您的代碼或github存儲庫中的graph.js
代碼中實現。
另外,似乎我們必須在授權碼授予流程中生成訪問令牌才能完成操作。 就像在測試中一樣,當我使用僅應用程序的流訪問令牌來授權操作時,出現了Authorization_RequestDenied
錯誤,並且圖形服務器向我返回了以下消息:
“ message”:“權限不足,無法完成操作。”
您可以參考https://github.com/OfficeDev/O365-Nodejs-Microsoft-Graph-Connect/獲取示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.