cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
kavitakashish83
New Member

Auto Sign-in to Embed Power BI report in web application

Hi All,

 

I am able to show filtered power BI reports in a web application. But I need to auto sign-in using c# to AZURE ACTIVE DIRECTORY to access power BI reports.

 

Below is my ACTIVE DIRECTORY PATH :

 

https://login.windows.net/common/oauth2/authorize/?response_type=code&client_id={Client ID}&resource=https%3a%2f%2fanalysis.windows.net%2fpowerbi%2fapi&redirect_uri=http%3a%2f%2flocalhost%3a49898%2fRedirect.aspx

 

Any suggestions/comment/ solution on this would be highly appreaciated?

 

Thanks

Kavita

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft Eric_Zhang
Microsoft

Re: Auto Sign-in to Embed Power BI report in web application

@kavitakashish83

 

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);

 

View solution in original post

4 REPLIES 4
Microsoft Eric_Zhang
Microsoft

Re: Auto Sign-in to Embed Power BI report in web application

@kavitakashish83

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.

Capture.PNG

 

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}

 

kavitakashish83
New Member

Re: Auto Sign-in to Embed Power BI report in web application

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

Microsoft Eric_Zhang
Microsoft

Re: Auto Sign-in to Embed Power BI report in web application

@kavitakashish83

 

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);

 

View solution in original post

sagarmp02
Regular Visitor

Re: Auto Sign-in to Embed Power BI report in web application

How to do same thing in .net core web api?

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors