【问题标题】:How to access Azure AD using Azure Function App in Node.js如何在 Node.js 中使用 Azure Function App 访问 Azure AD
【发布时间】:2019-07-08 05:57:25
【问题描述】:

我可以使用 Azure Functions 访问 Azure AD 信息吗?我想使用 SendGrid 发送电子邮件并从 AD 中获取电子邮件。我从哪里开始做这件事?谢谢

【问题讨论】:

    标签: javascript node.js azure azure-active-directory azure-functions


    【解决方案1】:

    是的,你可以。主要步骤是请求访问令牌。然后使用此访问令牌到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);
      }
    });
    

    【讨论】:

    • 开始工作了!谢谢!我按照您的link to call microsoft graph api 上的步骤 1-5 进行操作。首先与邮递员一起使用。然后在 Azure 中,我使用 POST 的请求模块来获取令牌(必须使用 x-www-form-urlencoded)。然后使用 https 模块获取用户的广告详细信息。
    猜你喜欢
    • 1970-01-01
    • 2018-06-11
    • 2018-08-24
    • 2022-01-06
    • 2021-06-03
    • 2020-05-10
    • 1970-01-01
    • 2020-05-23
    • 1970-01-01
    相关资源
    最近更新 更多