I am trying to get a sample power BI embed (user owns data mode) working in an angular5 application. Below is what I have done so far:
- Installed powerbi & powerbi client npm packages.
- I have created an AAD app and given all access to powerbi apis.
Below is the code of my component:
import { Component, OnInit } from '@angular/core';
import * as pbicli from 'powerbi-client';
import {AuthenticationService} from '../authentication';
@Component({
selector: 'app-powerbi-qna',
templateUrl: './powerbi-qna.component.html',
styleUrls: ['./powerbi-qna.component.scss']
})
export class PowerbiQnaComponent implements OnInit {
embedToken: string;
constructor(private authSvc: AuthenticationService) { }
ngOnInit() {
// get embed tokens
this.loadDashboard();
}
loadDashboard() {
// Read embed application token from textbox
this.displayDashboard(this.authSvc.getCachedToken());
}
displayDashboard(token: string) {
const embedUrl = 'https://app.powerbi.com/reportEmbed?reportId=<reportid>';
const embedReportId = '<reportid>';
const config = {
type: 'report',
tokenType: 0,
accessToken: token,
embedUrl: embedUrl,
id: embedReportId,
permissions: 7,
settings: {
}
};
// Get a reference to the embedded report HTML element
const embedContainer = <HTMLElement>document.getElementById('powerBiEmbed');
const powerbi = new pbicli.service.Service(pbicli.factories.hpmFactory, pbicli.factories.wpmpFactory, pbicli.factories.routerFactory);
// Embed the report and display it within the div container.
const report = powerbi.embed(embedContainer, config);
// Report.off removes a given event handler if it exists.
report.off('loaded');
// Report.on will add an event handler which prints to Log window.
report.on('loaded', function() {
console.log('Loaded');
});
report.on('error', function(event) {
console.log(event.detail);
report.off('error');
});
report.off('saved');
report.on('saved', function(event) {
console.log(event.detail);
});
}
}
But things are not working and I get below exception in console: GET https://wabi-west-europe-redirect.analysis.windows.net/metadata/cluster 403 (Forbidden)
I am trying to access the powerbi using the loggedin user's license (User owns data) What am I missing here?