Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
droe1
Frequent Visitor

Utilizing RLS tokens in non-.NET app

We have been using PowerBI Pro successfully for a while now in an ISV scenario. Our app owns the data, and we are embedding reports. We have a DataGateway connected to an on-premise MySQL server. We want to begin using RLS. Our app is in PHP; we can't utilize .NET code.

 

We have no trouble obtaining an RLS token. (We cleared those barriers.) We can submit username and role information as demonstrated in the API docs. We can get back a token via the GenerateToken endpoint of the API.

 

Once we have this token in hand, how do we use it? I assumed that we could feed it into the JavaScript library (Microsoft) much as we did with our auth token. However, this gives a "403 Forbidden" error. 

 

Thus my question is: I've managed to fetch an RLS-augmented token via the API. Now (without .NET), how do I utilize the token?

 

 

 

2 REPLIES 2
v-jiascu-msft
Employee
Employee

Hi @droe1,

 

Since you have gotten the token, the rest steps could be finished by your own application. Maybe you can embed the contents with powerbi-client-JS package. Please refer to https://github.com/Microsoft/PowerBI-JavaScript.

Below is a demo that is a single html page with all the JS scripts.

<html>
<head>
	<title>
		Embed in a single page Test
	</title>
	<style>
        div {
            height: 680px;
            width: 320px;
        }
    </style>
</head>
<body>
<script>
window.onload = function() {
// your token
    var txtAccessToken = "Your token";

// Read embed URL from textbox
var txtEmbedUrl = "https://app.powerbi.com/reportEmbed?reportId=a873e468-a5215950b&groupId=70cdd6cb98ed9b65";

// Read report Id from textbox
var txtEmbedReportId = "a873e461215950b";

// Read embed type from radio
//var tokenType = "AAD token"; 0: AAD token, 1: embed token.
    var tokenType = 1;
    
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;

// We give All permissions to demonstrate switching between View and Edit mode and saving report.
var permissions = models.Permissions.All;

// Embed configuration used to describe the what and how to embed.
// This object is used when calling powerbi.embed.
// This also includes settings and options such as filters.
// You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
var config= {
    type: 'report',
    tokenType: tokenType == '0' ? models.TokenType.Aad : models.TokenType.Embed,
    accessToken: txtAccessToken,
    embedUrl: txtEmbedUrl,
    id: txtEmbedReportId,
    permissions: permissions,
    settings: {
        layoutType: models.LayoutType.MobilePortrait
    }
};

// Get a reference to the embedded report HTML element
var embedContainer = $('#container')[0];



    var report = powerbi.load(embedContainer, config);

    report.on("loaded", function () {
        report.render(config);
    });

report.on("error", function(event) {
    Log.log(event.detail);

    report.off("error");
});

report.off("saved");
report.on("saved", function(event) {
    Log.log(event.detail);
    if(event.detail.saveAs) {
        Log.logText('In order to interact with the new report, create a new token and load the new report');
     }
 })
 }
 </script>
 <script src="../node_modules/jquery/dist/jquery.js"></script>
    <script src="../node_modules/es6-promise/dist/es6-promise.js"></script>
    <script src="../node_modules/powerbi-client/dist/powerbi.js"></script>
    <script src="scripts/codesamples.js"></script>   
    <script src="scripts/index.js"></script>
    <script src="scripts/utils.js"></script>
    <script src="scripts/logger.js"></script>
    <script src="scripts/session_utils.js"></script>
    <script src="scripts/function_mapping.js"></script>
    <script src="scripts/report.js"></script>  
    <script src="scripts/step_samples.js"></script>
    <script src="scripts/step_embed.js"></script>
    <script src="scripts/step_interact.js"></script>
<div id = "container"></div>

 </body>
 </html>

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for the response! I'm working on implementing some configuration you mentioned. We have always been using the JS library you mentioned, so we're on the same page.

 

What is the purpose of "tokenType"? 
We are in an app-owns-data scenario, btw.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.