5

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:

  1. Installed powerbi & powerbi client npm packages.
  2. 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?

Unnie
  • 918
  • 8
  • 30
  • can you perhaps share the content & full response (w/ headers) for that 403? – RBreuer Apr 01 '18 at 14:23
  • 2
    did you found the solution? if you have the solution can you please post the entire steps to integrate PowerBI in angular, it would be helpful to us? – Krishnan Apr 10 '18 at 19:35

8 Answers8

3

I had the same problem. For me the solution was that I was using the wrong tokenType. https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embedding-Basics states that for "Application owned" data Embed should be used.

From https://github.com/Microsoft/powerbi-models/blob/baaaf184d4966b09094a2539a538bf10c6cb69c4/src/models.ts:

export enum TokenType {
    Aad,
    Embed
}
Martin
  • 880
  • 8
  • 20
  • 1
    But I wanted to access the power bi as the logged in user (User owns data). Shouldn't I be using AAD in that case? – Unnie Mar 27 '18 at 15:16
  • Perhaps I misunderstand you but I think that the TokenType determines who owns the PowerBi license. In our case our customers use our license thus we use embed. For user separation we use a role in the PowerBi report. – Martin Mar 28 '18 at 12:08
  • 1
    I want to use the powerBI with user licenses and user roles. So shouldn't I be using AAD? Embed token is used for scenario where the user does not have license (for eg: customers in a public website) and so we create a service account which has license. – Unnie Mar 28 '18 at 15:19
  • @Martin, could you share embedUrl (with obfuscated guids), and how did you get it? I have change `tokenType` to Embed, but still have 403 on `GET clusters` with error in browser console `detailedMessage: "Fail to initialize - Could not resolve cluster" errorCode: "403"` And i have initialized azure powerbi embedded service, connected app with them... – kore666 Oct 10 '18 at 10:35
1

Please refer my article which contains the steps to embed powerbi reports in angular application. This article contains the steps to deploy the report under a workspace, grant the required permissions in Azure AD, also granting the admin-consent related to PowerBI embedded etc. https://snkrishnan1.wordpress.com/2018/06/25/embed-power-bi-reports-in-angular-5-application/

Krishnan
  • 958
  • 5
  • 21
  • 44
  • Hi @Krishnan. Im working on your tuitorial. Thanks for sharing. Im working on .net core Angular application. Can you help me with these? – S.Rusdana Oct 25 '18 at 15:43
  • @Rusdana, can you please brief me about the issue you are facing? what are steps you have taken so far, any exceptions you are getting? – Krishnan Oct 27 '18 at 02:00
0

I had similar problems. Hopefully this helps.

Some PowerBI resources have group ids and some don't. If you omit the group id then you'll get a 403 Forbidden.

My embedUrl looks like this:

embedUrl: `https://app.powerbi.com/${PbiType}Embed?${PbiType}Id=${ResourceId}` + (GroupId ? `&groupId=${GroupId}` : ''),

Taul
  • 2,113
  • 1
  • 14
  • 18
0

I am running into the same problem. As @RBreuer asked for the full header, here are mine:

Request (as CURL, exported from Chrome)

curl 'https://wabi-west-europe-redirect.analysis.windows.net/metadata/cluster' -H 'Authorization: EmbedToken eyJ0eXAiOiJKV1QiLCJhbGciOiJSU....' -H 'Origin: https://app.powerbi.com' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9' -H 'RequestId: b6837253-d152-8325-08b9-227c683363d3' -H 'ActivityId: b91d1b42-3d72-4cd2-8094-709af013cf83' -H 'Accept: application/json, text/plain, /' -H 'Referer: https://app.powerbi.com/reportEmbed?reportId=53f75214-7b5f-4264-b7ea-xxxxxxxxxx&groupId=b580bbcc-75ce-4347-bbfd-xxxxxxxxx' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36' -H 'Connection: keep-alive' --compressed

Answer is:

Request URL: https://wabi-west-europe-redirect.analysis.windows.net/metadata/cluster
Request Method: GET
Status Code: 403 Forbidden
Remote Address: 13.95.158.123:443
Referrer Policy: no-referrer-when-downgrade

I am running Angular6 with latest powerbi-client.

I receive the accessToken with adal (python lib) in my backend for a prev. configured Azure Application with native support proxying my pbi-report as described in the PBI-Docs for App Owns Data configuration.

Hope that information help someone to solve the problem or at least point into the right direction ;)

Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82
Patrick P.
  • 109
  • 8
0

@Patrick P. : Your Authorization header value of 'EmbedToken ey....' suggests you're accidentally using tokenType: Embed (1) in your embed config.

Rule of thumb: ey prefix of the token usually suggests AAD TokenType (0), H4 prefix suggests EmbedToken (1).

As @Taul answered too, this is usually the problem with wrong tokens. Other options can be wrong groupId & reportId in config.

RBreuer
  • 1,371
  • 1
  • 7
  • 17
0

Use the following code to embed your PowerBI report into Angular application. It works perfectly for me. You need to fill accessToken, embedUrl, embedReportId.

showReport() {
    // Report's Secured Token
    let accessToken = 'Access Token';
    // Embed URL
    let embedUrl = 'Embed URL';
    // Report ID
    let embedReportId = 'Report ID';
    let config = {
      type: 'report',
      accessToken: accessToken,
      embedUrl: embedUrl,
      id: embedReportId,
      permissions: pbi.models.Permissions.All,
      settings: {
        localeSettings: {
          language: "en",
          formatLocale: "es"
        }
      }
    };
    // Grab the reference to the div HTML element that will host the report.
    let reportContainer = <HTMLElement>document.getElementById('reportContainer');
    // Embed the report and display it within the div container.
    let powerbi = new pbi.service.Service(pbi.factories.hpmFactory, pbi.factories.wpmpFactory, pbi.factories.routerFactory);
    let report = powerbi.embed(reportContainer, config);
    var rep = powerbi.get(reportContainer);

    //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");
    });    
  }
Chamila Maddumage
  • 3,304
  • 2
  • 32
  • 43
0

You can try this code:

showReports() {
  const config = <IEmbedConfigurationBase><any>{ // add this type of object  <IEmbedConfigurationBase><any>
type: 'report',
uniqueId: 'your-report-id ',
id: 'your-report-id ',
tokenType: 'Embed Token',
settings: {
  navContentPaneEnabled: false,
  filterPaneEnabled: false
},
embedUrl: 'your-embed url',
accessToken: 'your-access-token'
};

 const reportsContainer = <HTMLElement>document.getElementById(
     'reportsContainer'
    );

const powerbi = new pbi.service.Service(
   pbi.factories.hpmFactory,
   pbi.factories.wpmpFactory,
   pbi.factories.routerFactory
 );
const report = powerbi.embed(
  reportsContainer,
  config
);
} 

For more refernces - Interface IEmbedConfigurationBase

Nodejs POC to generate accessToken

Vaibhav Gaikwad
  • 811
  • 2
  • 12
  • 21
-2

power bi service might be not available in some regions .Please check availability of services in your regions.other reason may be you should create native app and then try to embed.

Kamalakar
  • 389
  • 2
  • 9