Skip to content

Instantly share code, notes, and snippets.

View krishnaanaril's full-sized avatar
🎯
Focusing

Krishna Mohan krishnaanaril

🎯
Focusing
View GitHub Profile
@krishnaanaril
krishnaanaril / DashboardComponent.ts
Last active October 5, 2018 10:00
Minimal DashboardComponent file
import { Component, OnInit } from '@angular/core';
import * as pbi from 'powerbi-client';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.less']
})
export class DashboardComponent implements OnInit {
@krishnaanaril
krishnaanaril / app-data-embedPowerBIReport.ts
Created October 5, 2018 10:08
Method to embed Power BI report
embedPowerBIReport() {
this.service.getReportEmbedToken().subscribe((res) => {
let response = res.json();
let Token = response.EmbedToken;
const config = {
type: 'report',
tokenType: pbi.models.TokenType.Embed,
id: response.Id,
embedUrl: response.EmbedUrl,
accessToken: Token.token,
@krishnaanaril
krishnaanaril / app-data-embedPowerBITile.ts
Created October 5, 2018 10:09
Method to embed Power BI Tiles
embedPowerBITile() {
this.service.getTileEmbedToken().subscribe((res) => {
let response = res.json();
let Token = response.EmbedToken;
const config = {
type: 'tile',
tokenType: pbi.models.TokenType.Embed,
id: response.Id,
embedUrl: response.EmbedUrl,
accessToken: Token.token,
@krishnaanaril
krishnaanaril / adal.service.ts
Created October 5, 2018 10:14
Azure Active Directory authentication library service
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, Subscriber, of } from 'rxjs';
import { switchMap, map } from 'rxjs/operators';
import { RequestOptions } from '@angular/http';
import { adal } from 'adal-angular';
import * as AuthenticationContext from 'adal-angular/lib/adal'
import { environment } from '../../environments/environment';
@krishnaanaril
krishnaanaril / getReportsInGroup.ts
Created October 5, 2018 10:17
Calling Power BI API to get reports in group
public getReportsInGroup(groupId: string){
const headers = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': `Bearer ${this._context.getCachedToken(environment.powerBIEndpoint)}`
}); // this._context is the ADAL AuthenticationContext object
return this.http.get(`https://api.powerbi.com/v1.0/myorg/groups/${groupId}/reports`, { headers: headers });
}
@krishnaanaril
krishnaanaril / Web.config
Created October 5, 2018 10:21
Web.config settings for the API that generates embed tokens
<!--Id of the Azure AD application-->
<add key="applicationId" value="" />
<!--Id of the workspace where your reports reside-->
<add key="workspaceId" value="" />
<!-- The id of the report to embed. If empty, will use the first report in group -->
<add key="reportId" value="" />
<add key="authorityUrl" value="https://login.windows.net/common/oauth2/authorize/" />
<add key="resourceUrl" value="https://analysis.windows.net/powerbi/api" />
@krishnaanaril
krishnaanaril / environment.ts
Last active October 5, 2018 10:26
Angular environment settings for configuring Azure ADAL
export const environment = {
production: false,
apiEndPoint: "", // api endpoint for generationg embed tokens (for app-owns-data)
powerBIEndpoint: "https://analysis.windows.net/powerbi/api",
groupId: "", // similar to workspace id
adalConfig: {
tenant: '', //tenant id of your organization
clientId: '', // client id of your azure ad application
cacheLocation: 'localStorage', // Default is sessionStorage
redirectUri:`${window.location.origin}/` ,
@krishnaanaril
krishnaanaril / getDashboardsInGroup.ts
Created October 5, 2018 10:27
Calling Power BI API to get dashboards in group
public getDashboardsInGroup(groupId: string){
const headers = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': `Bearer ${this._context.getCachedToken(environment.powerBIEndpoint)}`
});// this._context is the ADAL AuthenticationContext object
return this.http.get(`https://api.powerbi.com/v1.0/myorg/groups/${groupId}/dashboards`, { headers: headers });
}
@krishnaanaril
krishnaanaril / getTilesInGroup.ts
Created October 5, 2018 10:29
Calling Power BI API to get tiles in group
public getTilesInGroup(groupId: string, dashboardKey: string){
const headers = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': `Bearer ${this._context.getCachedToken(environment.powerBIEndpoint)}`
});// this._context is the ADAL AuthenticationContext object
return this.http.get(`https://api.powerbi.com/v1.0/myorg/groups/${groupId}/dashboards/${dashboardKey}/tiles`, { headers: headers });
}
@krishnaanaril
krishnaanaril / user-data-embedPowerBIDashboard.ts
Last active October 5, 2018 11:41
Embed Power BI dashboard for organization
// get access token
getToken() {
this.adalSrv.context.acquireToken(environment.powerBIEndpoint, (error, token) => {
if (error || !token) {
// TODO: Handle error obtaining access token
console.error('ERROR:\n\n' + error);
return;
}
// Get available dashboards
this.adalSrv.getDashboardsInGroup(environment.groupId).subscribe(res=>{