Forum Discussion
Auto Sign-in to Embed Power BI report in web application
- 9 years ago
Then see this demo APP OWNS DATA. On license aspect, do note this approach would need Power BI premium license if you'd share your report to the users without Power BI account.
// Create a user password cradentials. var credential = new UserPasswordCredential(Username, Password); // Authenticate using created credentials var authenticationContext = new AuthenticationContext(AuthorityUrl); var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);
What do you mean auto sign-in here?
The URL in your post would redirect you to the redirect_uri appending a code in the url.
in next step, you can send a POST request with the code above and get the access token.
POST /common/oauth2/token HTTP/1.1
Host: login.windows.net
Content-Type: application/x-www-form-urlencoded
client_secret={client_secrect}&client_id={client_id}&grant_type=authorization_code&resource=https://analysis.windows.net/powerbi/api&redirect_uri={your redirect url}&code={code from above}
Thanks for the reply.
Auto Sign-in means user doesn't need to login into POWER BI Azure site.
Below is my complete code:
string redirectUri = String.Format("{0}Redirect.aspx", Properties.Settings.Default.RedirectUrl);
string authorityUri = Properties.Settings.Default.AADAuthorityUri;
// Get the auth code
string code = Request.Params.GetValues(0)[0];
// Get auth token from auth code
TokenCache TC = new TokenCache();
AuthenticationContext AC = new AuthenticationContext(authorityUri, TC);
ClientCredential cc = new ClientCredential(Properties.Settings.Default.ClientID,Properties.Settings.Default.ClientSecret);
AuthenticationResult AR = AC.AcquireTokenByAuthorizationCode(code, new Uri(redirectUri), cc);
Session[PowerBI.authResultString] = AR;
Response.Redirect("~/PowerBI.aspx", false);
Kindly suggest!
Thanks
Kavita
- Eric_Zhang9 years agoMicrosoft Employee
Then see this demo APP OWNS DATA. On license aspect, do note this approach would need Power BI premium license if you'd share your report to the users without Power BI account.
// Create a user password cradentials. var credential = new UserPasswordCredential(Username, Password); // Authenticate using created credentials var authenticationContext = new AuthenticationContext(AuthorityUrl); var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential); - Anonymous5 years agoNot applicable
Hi Kavita,
Where Can I write this script? Because I am facing same probelm with login. Is it possible only in power bi permium verion?
Thanks,
Pooja