【发布时间】:2019-07-08 05:57:25
【问题描述】:
我可以使用 Azure Functions 访问 Azure AD 信息吗?我想使用 SendGrid 发送电子邮件并从 AD 中获取电子邮件。我从哪里开始做这件事?谢谢
【问题讨论】:
标签: javascript node.js azure azure-active-directory azure-functions
我可以使用 Azure Functions 访问 Azure AD 信息吗?我想使用 SendGrid 发送电子邮件并从 AD 中获取电子邮件。我从哪里开始做这件事?谢谢
【问题讨论】:
标签: javascript node.js azure azure-active-directory azure-functions
是的,你可以。主要步骤是请求访问令牌。然后使用此访问令牌到call microsoft graph api 从 AD 中获取电子邮件。
您可以使用client credentials flow 获取访问令牌。这是供您参考的代码。
var AuthenticationContext = require('adal-node').AuthenticationContext;
var authorityHostUrl = 'login.microsoftonline.com';
var tenant = '{your_tenant_name}';
var authorityUrl = authorityHostUrl + '/' + tenant;
var resource = 'https://graph.microsoft.com'; // URI that identifies the resource for which the token is valid.
var applicationId = '{your_application_id}';
var clientSecret = '{your_client_secret}';
var context = new AuthenticationContext(authorityUrl);
context.acquireTokenWithClientCredentials(resource, applicationId, clientSecret, function(err, tokenResponse) {
if (err) {
console.log('well that didn\'t work: ' + err.stack);
} else {
console.log(tokenResponse);
}
});
【讨论】: