[英]How to generate Authorization Bearer token using client ID , tenant Id, Client secret of azure AD using NodeJs for calling REST API?
I am able to generate the token in Postman: using the following details.我能够在 Postman 中生成令牌:使用以下详细信息。
tenant_id: 09872XXXXXXXXXXXXXXXXXX
grant_type: client_credentials
client_id: d7b7e-ighewiojwoei9-868767
client_secret:adat-XXXXXX-diupi825tfsq38XXXXX
resource: https://management.azure.com/
Want to achieve the same using NodeJs?想要使用 NodeJs 实现相同的目标吗?
What you are using is the Azure AD client credential flow v1.0 , to do this in node.js, you could use the ADAL for Node.js
, change the resource
to https://management.azure.com/
, the applicationId
is the client_id
you used. What you are using is the Azure AD client credential flow v1.0 , to do this in node.js, you could use the
ADAL for Node.js
, change the resource
to https://management.azure.com/
, the applicationId
is the client_id
you用过的。
var AuthenticationContext = require('adal-node').AuthenticationContext;
var authorityHostUrl = 'https://login.windows.net';
var tenant = 'myTenant.onmicrosoft.com'; // AAD Tenant name.
var authorityUrl = authorityHostUrl + '/' + tenant;
var applicationId = 'yourApplicationIdHere'; // Application Id of app registered under AAD.
var clientSecret = 'yourAADIssuedClientSecretHere'; // Secret generated for app. Read this environment variable.
var resource = 'https://management.azure.com/'; // URI that identifies the resource for which the token is valid.
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);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.