使用Azure应用程序服务身份验证将Azure功能作为多租户应用程序连接到Microsoft Graph
我一直在研究如何将azure功能连接到任何用户的office 365图形,以查询他们的收件箱,但没有成功。我需要帮助了解执行以下操作的正确方法: 当用户向http触发函数发出http get请求时,它应该:使用Azure应用程序服务身份验证将Azure功能作为多租户应用程序连接到Microsoft Graph,azure,azure-active-directory,microsoft-graph-api,azure-functions,Azure,Azure Active Directory,Microsoft Graph Api,Azure Functions,我一直在研究如何将azure功能连接到任何用户的office 365图形,以查询他们的收件箱,但没有成功。我需要帮助了解执行以下操作的正确方法: 当用户向http触发函数发出http get请求时,它应该: 提示用户登录其Microsoft工作帐户 请求访问其收件箱的权限 查询他们的收件箱以获取未读邮件的计数 回复未读邮件数 这应该适用于调用该函数的任何用户,无论他们正在访问哪个azure active directory实例 这可能吗 如果是这样,有人能解释一下如何配置azure功能来实现这一
Stewart您应该能够找到关于另一个StackOverflow问题的信息:
关于如何注册AAD多租户应用程序,您可以在此处找到更多信息:。主要技巧是转到“高级”选项卡并清除“颁发者URL”字段。您应该能够找到有关此其他StackOverflow问题的信息:
关于如何注册AAD多租户应用程序,您可以在此处找到更多信息:。主要的技巧是转到“高级”选项卡并清除“颁发者URL”字段。我已经想出了如何做到这一点。建议的解决方案只是从Microsoft Graph返回用户的详细信息,而不是收件箱计数
var request = require('request');
module.exports = function (context, req) {
var parameters = {
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
client_id: process.env.WEBSITE_AUTH_CLIENT_ID,
client_secret: process.env.WEBSITE_AUTH_CLIENT_SECRET,
assertion: req.headers['x-ms-token-aad-id-token'],
resource: 'https://graph.microsoft.com',
requested_token_use: 'on_behalf_of'
};
var tenant = req.headers['x-ms-client-principal-name'].replace(/.*@/, "");
request.post('https://login.microsoftonline.com/'+tenant+'/oauth2/token', {form: parameters}, function (aadErr, aadResponse, aadMsg) {
var msgJson = JSON.parse(aadMsg);
request.get('https://graph.microsoft.com/v1.0/me/', {'auth': {'bearer': msgJson.access_token}}, function (err, response, msg) {
context.res = {
body: msg
};
context.done();
});
});
};
我已经知道怎么做了。建议的解决方案只是从Microsoft Graph返回用户的详细信息,而不是收件箱计数
var request = require('request');
module.exports = function (context, req) {
var parameters = {
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
client_id: process.env.WEBSITE_AUTH_CLIENT_ID,
client_secret: process.env.WEBSITE_AUTH_CLIENT_SECRET,
assertion: req.headers['x-ms-token-aad-id-token'],
resource: 'https://graph.microsoft.com',
requested_token_use: 'on_behalf_of'
};
var tenant = req.headers['x-ms-client-principal-name'].replace(/.*@/, "");
request.post('https://login.microsoftonline.com/'+tenant+'/oauth2/token', {form: parameters}, function (aadErr, aadResponse, aadMsg) {
var msgJson = JSON.parse(aadMsg);
request.get('https://graph.microsoft.com/v1.0/me/', {'auth': {'bearer': msgJson.access_token}}, function (err, response, msg) {
context.res = {
body: msg
};
context.done();
});
});
};
我已将azure功能的azure应用程序服务身份验证设置为多租户应用程序,并使用express设置对azure active directory进行身份验证。我可以作为同一租户中的用户成功登录