Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerBI Entitlements #196

Open
wants to merge 1 commit into
base: 1.1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion modules/quanthub_core/src/PowerBIEmbedConfigs.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,78 @@ public function getPowerBiAccessToken() {
return $oidc_response->access_token;
}

/**
* Get PowerBI dataset details.
*/
public function getPowerBiDataset($token, $datasetId) {
$powerbiAPIURL = 'https://api.powerbi.com/v1.0/myorg/groups/' . $this->getWorkspaceID() . '/datasets/' . $datasetId;

try {
$request = $this->httpClient->request(
'GET',
$powerbiAPIURL,
[
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Cache-Control' => 'no-cache',
],
'connect_timeout' => 30,
'allow_redirects' => [
'max' => 10,
],
]
);
}
catch (\Exception $e) {
$this->loggerFactory->error('getPowerBiDataset: ' . $e->getMessage());
return NULL;
}

$datasetResponse = json_decode($request->getBody(), TRUE);
return $datasetResponse;
}

/**
* Get PowerBI Embed Token.
*/
public function getPowerBiEmbedToken($token, $reportId, $datasetIds) {
$powerbiAPIURL = 'https://api.powerbi.com/v1.0/myorg/GenerateToken';
$powerbiUser = getenv('POWERBI_PUBLIC_USER');
$powerbiRole = getenv('POWERBI_PUBLIC_ROLE');

$entitledDatasets = [];
foreach ($datasetIds as $datasetId) {
$response = $this->getPowerBiDataset($token, $datasetId);
if ($response['isEffectiveIdentityRequired'] && $response['isEffectiveIdentityRolesRequired']) {
$entitledDatasets[] = $datasetId;
}
}

$datasets = [];
foreach ($datasetIds as $datasetId) {
$datasets[] = [
'id' => $datasetId,
'xmlaPermissions' => 'ReadOnly',
];

}

$payload = [
'accessLevel' => 'View',
'datasets' => $datasets,
'reports' => [['id' => $reportId]],
'targetWorkspaces' => [['id' => $this->getWorkspaceID()]],
];

if (count($entitledDatasets) > 0) {
$payload['identities'] = [
[
'username' => $powerbiUser,
'roles' => [$powerbiRole],
'datasets' => $entitledDatasets,
],
];
}

$payload_json = json_encode($payload);

try {
Expand Down
Loading