I want to configure MSAL with Nodejs. But I am getting error from terminal that when I execute this line.
The error I am getting is :
(node:25500) UnhandledPromiseRejectionWarning: TypeError: this.getTelemetryManagerFromConfig is not a function
at Object.UserAgentApplication (D:\powerbi embed\NodeJS\App Owns Data\node_modules\msal\lib-commonjs\UserAgentApplication.js:87:38)
at Object.getAuthenticationToken (D:\powerbi embed\NodeJS\App Owns Data\authentication.js:11:31)
at generateEmbedToken (D:\powerbi embed\NodeJS\App Owns Data\app-owns-data-sample.js:33:32)
at Object.<anonymous> (D:\powerbi embed\NodeJS\App Owns Data\app-owns-data-sample.js:130:1)
at Module._compile (internal/modules/cjs/loader.js:955:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10)
at Module.load (internal/modules/cjs/loader.js:811:32)
at Function.Module._load (internal/modules/cjs/loader.js:723:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10)
at internal/main/run_main_module.js:17:11
(node:25500) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was
not handled with .catch(). (rejection id: 2)
(node:25500) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.PS D:\powerbi embed\NodeJS\App Owns Data>
This is the Code:
var msal = require('msal');
// var adal = require('adal-node');
var fs = require('fs');
var https = require('https');
var config = require(__dirname + '/config.json');
console.log(config);
console.log(msal);
**const msalInstance = msal.UserAgentApplication(config);
console.log(msalInstance);**
Here is my config file.
{
"authorityUrl" : "https://login.microsoftonline.com/common/",
"resourceUrl" : "https://analysis.windows.net/powerbi/api",
"apiUrl" : "https://api.powerbi.com/",
"appId" : "**********************************",
"clientId" : "**********************************",
"workspaceId" : "**********************************",
"reportId" : "**********************************",
"username" : "**********************************",
"password" : "********************"
}
Here is the function where this shows the error at msal/lib-commonjs/UserAgentApplication.js File:
function UserAgentApplication(configuration) {
// callbacks for token/error
this.authResponseCallback = null;
this.tokenReceivedCallback = null;
this.errorReceivedCallback = null;
// Set the Configuration
this.config = Configuration_1.buildConfiguration(configuration);
// Set the callback boolean
this.redirectCallbacksSet = false;
this.logger = this.config.system.logger;
this.clientId = this.config.auth.clientId;
this.inCookie = this.config.cache.storeAuthStateInCookie;
**this.telemetryManager = this.getTelemetryManagerFromConfig(this.config.system.telemetry, this.clientId);** //error is referring to this line.
}
Please help. Thanks in Advance.
When you create your instance of UserAgentApplication, use
const msalInstance = new msal.UserAgentApplication(config);
Emphasis on the keyword new :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.