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
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
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.