Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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)
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 |
| User | Count |
|---|---|
| 11 | |
| 7 | |
| 4 | |
| 4 | |
| 3 |