March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi,
I am struggling to adapt any of the example code to silently get an embed token. My web app is built on the Django framework with an app owns data model (with RLS).
Is there a POST/GET solution that is similar to the the CLI tool that I can use? Or is it possible to build an embed token outright?
I am sorry if I this is a silly question, I am quite new to Python and Web apps.
Thanks in advance.
Solved! Go to Solution.
I actually was able to figure it out with the help of a Microsoft Case Study I found.
You don't need any kind of API for the embed token itself, you can build the JWT outright if you already have an access key.
import time import jwt def generate_token(access_key, workspace_id, report_id, workspace_collection, brand): """Generate JWT token.""" # token times start = time.time() end = start + 60 * 60 # create tokens headers = { "typ": "JWT", "alg": "HS256", } payload = { "wid": workspace_id, "rid": report_id, "wcn": workspace_collection, "username": VALID USERNAME, "roles": [ROLE1, ROLE2, ETC], "iss": "PowerBISDK", "ver": "0.2.0", "aud": "https://analysis.windows.net/powerbi/api", "nbf": start, "exp": end, } return jwt.encode(key=access_key, headers=headers, payload=payload)
@adamwallace3 wrote:
Hi,
I am struggling to adapt any of the example code to silently get an embed token. My web app is built on the Django framework with an app owns data model (with RLS).
Is there a POST/GET solution that is similar to the the CLI tool that I can use? Or is it possible to build an embed token outright?
I am sorry if I this is a silly question, I am quite new to Python and Web apps.
Thanks in advance.
You can use below POST REST API to get the access Bearer token.
POST /common/oauth2/token HTTP/1.1 Host: login.windows.net Cache-Control: no-cache Content-Type: application/x-www-form-urlencoded client_id={client_id}&grant_type=password&resource=https://analysis.windows.net/powerbi/api&username={powerbi account}&password={powerbi account password}
And then use this API GenerateToken to get embedded token for dashboards/reports/datasets. Note that it seems the RLS now is only avalaible for embedded reports not for dashboards. See this thread.
By the way, when using App Owns data, you'll have to purchase Power BI Premium license when promoting your solution to production.
I actually was able to figure it out with the help of a Microsoft Case Study I found.
You don't need any kind of API for the embed token itself, you can build the JWT outright if you already have an access key.
import time import jwt def generate_token(access_key, workspace_id, report_id, workspace_collection, brand): """Generate JWT token.""" # token times start = time.time() end = start + 60 * 60 # create tokens headers = { "typ": "JWT", "alg": "HS256", } payload = { "wid": workspace_id, "rid": report_id, "wcn": workspace_collection, "username": VALID USERNAME, "roles": [ROLE1, ROLE2, ETC], "iss": "PowerBISDK", "ver": "0.2.0", "aud": "https://analysis.windows.net/powerbi/api", "nbf": start, "exp": end, } return jwt.encode(key=access_key, headers=headers, payload=payload)
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
11 | |
3 | |
2 | |
2 | |
2 |