angular - 类型错误:无法读取未定义的属性(读取 'tokenType')
当我们尝试使用 Power BI Angular 库嵌入报表时,出现以下错误。
TypeError: Cannot read properties of undefined (reading 'tokenType')
at isSaaSEmbedWithAADToken (reportEmbed?navContentPaneEnabled=false&uid=ame7c8:586:38)
at getModelsAndExploration (reportEmbed?navContentPaneEnabled=false&uid=ame7c8:696:17)
at getModelsAndExplorationAndConceptualSchema (reportEmbed?navContentPaneEnabled=false&uid=ame7c8:840:9)
at xhr.onreadystatechange (reportEmbed?navContentPaneEnabled=false&uid=ame7c8:505:37)
这是我们用来嵌入报告的代码。
this.msalService.initialize().subscribe(() => {
this.msalService.acquireTokenSilent({
scopes: environment.powerBiConfig.scopes,
account: this.authService.getUser()
}).subscribe(async (result) => {
const embedConfig: pbi.service.IComponentEmbedConfiguration = {
type: 'report',
id: this.report.identifier,
accessToken: result.accessToken,
tokenType: models.TokenType.Aad,
embedUrl: 'https://app.powerbi.com/reportEmbed?navContentPaneEnabled=false',
settings: {
panes: {
filters: {
visible: false,
}
}
}
};
const defaultFilters = this.createDefaultFilters();
const powerBiReport: any = this.powerBiService.embed(this.reportContainer.nativeElement, embedConfig);
powerBiReport.on('loaded', async () => {
await powerBiReport.setFilters(defaultFilters);
});
});
});
在跟踪堆栈到 Power BI Embedded JS 文件(我们无法控制的文件)之后,我们能够确定问题的原因。以下函数期望传入一个配置:
function isSaaSEmbedWithAADToken(config) {
// Default token type is Aad (0)
const tokenType = config.tokenType || 0;
return (window.isSaasOrPaasEmbed === true) && (tokenType === 0);
}
然而,导致错误的那段代码实际上并没有传递配置。
if (isSaaSEmbedWithAADToken() && config.settings && config.settings.personalBookmarksEnabled) {
url += "&defaultBookmarkEnabled=true";
}
即使我们这边做错了什么,这是微软方面的一个漏洞。解决方法很简单,只需像代码的其他部分一样传递配置即可。
我们的设置中有什么问题导致了这个问题吗?Power BI Embedded 的 JS 文件似乎是闭源的。
答案#1
微软方面的问题已修复。https://github.com/microsoft/powerbi-client-angular/issues/66