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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
adolfomartinez
Frequent Visitor

Credencial "genérica" en Power BI Embedded

Buenos días!

 

Me podrían apoyar en saber cómo configurar una "credencial" genérica para que funcione el Power BI Embedded.

 

Actualmente en el código tengo mi credencial (correo y contraseña de Power BI), pero lo que pasa es que necesito activarle a mi correo la doble autenticación y, cuando eso sucede... mi Power BI Embedded ya no funciona porque no agarra la contraseña porque está activada la doble autenticación de Office.

 

Este es mi fragmento de código (Lo que está en rojo es donde pongo mi correo y contraseña):

 

 

 

 

protected void CargarReporte(string groupId, string reportId, string type)
{
string embedUrl = "";
string token = "";

string funcion = "";
EmbedToken embedToken;

try
{
// Create a user password cradentials.
//credential = new ClientCredential(Secrets.ClientID, Secrets.ClientSecret);
credential = new UserPasswordCredential(username, Secrets.Password);

// Authenticate using created credentials
Authorize().Wait();

using (var client = new PowerBIClient(new Uri(apiUrl), tokenCredentials))
{
if (type == "report")
{
//Report
embedToken = client.Reports.GenerateTokenInGroup(groupId, reportId, new GenerateTokenRequest(accessLevel: "View", datasetId: datasetId));
Report report = client.Reports.GetReportInGroup(groupId, reportId);

embedUrl = report.EmbedUrl;
token = embedToken.Token;

funcion = "Reporte('" + groupId + "','" + reportId + "','" + embedUrl + "','" + token + "');";
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", funcion, true);
}
else if (type == "dashboard")
{
//Dashboard
embedToken = client.Dashboards.GenerateTokenInGroup(groupId, reportId, new GenerateTokenRequest(accessLevel: "View", datasetId: datasetId));
Dashboard dashboard = client.Dashboards.GetDashboardInGroup(groupId, reportId);

embedUrl = dashboard.EmbedUrl;
token = embedToken.Token;

funcion = "Dashboard('" + groupId + "','" + reportId + "','" + embedUrl + "','" + token + "');";
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", funcion, true);
}
}
}
catch (Exception ex)
{
Response.Write("<script>alert('Error');</script>");
}
}

private static Task Authorize()
{
return Task.Run(async () => {
authenticationResult = null;
tokenCredentials = null;

var tenantSpecificURL = authorityUrl.Replace("common", tenantId);
var authenticationContext = new AuthenticationContext(authorityUrl);

//authenticationResult = await authenticationContext.AcquireTokenAsync(resourceUrl, credential);
authenticationResult = await authenticationContext.AcquireTokenAsync(resourceUrl, Secrets.ClientID, credential);

if (authenticationResult != null)
{
tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
}
});
}

1 REPLY 1
Syndicate_Admin
Administrator
Administrator

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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