Forum Discussion
Troubleshooting 'Get report failed' Error When Embedding Power BI Report in webpage
- 2 years ago
As I mentioned you need to use an App registration to surpass the Outh2
Please watch this video
https://m.youtube.com/watch?v=2RZkc_qrV1g&t=610s
You need to be aware using this method will only get you the last 30 days of data.
use jwt.io to validate that your token has the required scope.
Hi lbendlin , As you said I decoded both tokens, and I found different payload data for both tokens. The one which I got from 'Microsoft-Learn Try It Rest Api' have scopes and the other one which I got from the postman request have 'roles' instead of 'scopes'. I am posting a difference here.
Please advice me what should I do to obtain the access token that I received from 'Microsoft REST API Try It Console'
Payload data in token I got from 'Microsoft Try It' it
{
"rh": "0asdfaxxxxxxxxxxxxxxxxxxxxx",
"scp": "App.Read.All Capacity.Read.All Capacity.ReadWrite.All Content.Create Dashboard.Read.All Dashboard.ReadWrite.All Dataflow.Read.All Dataflow.ReadWrite.All Dataset.Read.All Dataset.ReadWrite.All Gateway.Read.All Gateway.ReadWrite.All Pipeline.Deploy Pipeline.Read.All Pipeline.ReadWrite.All Report.Read.All Report.ReadWrite.All StorageAccount.Read.All StorageAccount.ReadWrite.All Tenant.Read.All Tenant.ReadWrite.All UserState.ReadWrite.All Workspace.Read.All Workspace.ReadWrite.All",
"signin_state": [
"kmsi"
],
"sub": "xxxxxxxxxxxxx",
"tid": "TenantID",
"unique_name": "MyEmailId",
"upn": "MyEmailId",
"uti": "",
"ver": "1.0",
"wids": [
"xxxxxxxxxxxxxxxx"
]
}
Payload Data I got from Access Token which I got by Postman request
{
"rh": "0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"roles": [
"Tenant.ReadWrite.All",
"Tenant.Read.All"
],
"sub": "xxxxxxxxxxxxxxxxxxxxxxxx",
"tid": "Tenant Id",
"uti": "xxxxxxxxxxxxxxxxxxx",
"ver": "1.0"
}
- lbendlin2 years agoSuper User
You need scopes, not roles. You probably need to register an app and then use the app credentials in Postman.
- aj19732 years agoCommunity Champion
To embed reports you need to use App Registration. Tokens only last for 60 mins.
https://learn.microsoft.com/en-us/power-bi/developer/embedded/register-app?tabs=customers
- shravanighosh2 years agoFrequent Visitor
Hi aj1973 lbendlin , Thank you for your response. I have added the necessary scopes and now the solution is working. However, I want to embed this report for customers. And every time I have to log in with my Microsoft member account to generate the access token. If embedded for customers is there any way I can get embed token / access token without any login.
Current functionality: I am visiting this URL
programmatically
redirectURI = "https: //myApp/powerbi-report";
Which redirects to my application's uri powerbi-report and to handle it I am using a function which gets the code query string from the request. And then calls this endpoint to generate accessToken. For any reference, I am including a code here.
So, here it asks to log into the Microsoft Group Member Account.
I want to embed this report for my customers. So, it should be displayed without login. Like how we do using iFrame link of the report that it doesn't need any login or auth.public function getCode(Request $request){ $code = $request->code; $client = new Client(); $response = $client->request('POST', 'https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token', [ 'headers' => [ 'Content-Type' => 'application/x-www-form-urlencoded', ], 'form_params' => [ 'client_id' => 'CLIENT_ID, 'redirect_uri' => 'https://MY-APP-URL/reports/powerbi', 'grant_type' => 'authorization_code', 'code' => $code, 'client_secret' => 'CLIENT-SECRET', ], ]); $responseBody = $response->getBody()->getContents(); $responseData = json_decode($responseBody, true); $accessToken = $responseData['access_token']; return view('reports.powerbi')->with('data', $accessToken); }- aj19732 years agoCommunity Champion
As I mentioned you need to use an App registration to surpass the Outh2
Please watch this video
https://m.youtube.com/watch?v=2RZkc_qrV1g&t=610s
You need to be aware using this method will only get you the last 30 days of data.