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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

How to generate the authorization code and the access token to embed Powerbi in WebApplication


I am trying to embed the Powerbi report in a web application. As the initial step I am trying to generate the access token to embed.

As specified, I need to invoke a REST API for "Request an authorization code" as mentioned in the article 

 

In Restlet (Google Chrome Browser) I gave the following api url and the parameters using Get method request.

 

https://login.microsoftonline.com/common/oauth2/authorize?
client_id=bee215ce-***********-029dc0351a1e
&response_type=code
&redirect_uri=http://localhost/12345
&response_mode=query
&resource=https://service.contoso.com/
&state=12345

 

 

The Response object which I recevied is as below, but as per the article I am supposed to recevie the auth code which in turn I am supposed to use to get the access token. But the response object which I am receving back is not in the expected format.

GetAuthCodeIssues1.png


I am not sure what is the mistake I am doing it here? any ideas? How to generate the authorization code and then the access token?

1 ACCEPTED SOLUTION
v-micsh-msft
Employee
Employee

Hi,

 

Have you checked the following article?

How To: Get embed token using Get/Post only

The call to generate Access Token should be

"

POST: https://login.microsoftonline.com/common/oauth2/token
data: {
    grant_type: password
    scope: openid
    resource: https://analysis.windows.net/powerbi/api
    client_id: {Client ID}
    username: {PBI Account Username}
    password: {PBI Account Username}
}

--Returns Json:
 
{
    "token_type": "Bearer",
    "scope": "Report.Read.All ...",
    "expires_in": "xxxx",
    "ext_expires_in": "0",
    "expires_on": "xxxxxxxxxx",
    "not_before": "xxxxxxxxxxx",
    "resource": "https://analysis.windows.net/powerbi/api",
    "access_token": "eyJ0eXAi...",
    "refresh_token": "AQABA...",
    "id_token": "eyJ...."
}

"

The resource should be 

https://analysis.windows.net/powerbi/api

Make sure you have specified the other data part correctly.

for the process, please also check the document below:

Step 2: Get n authentication access token

 

Regards,

Michael

View solution in original post

1 REPLY 1
v-micsh-msft
Employee
Employee

Hi,

 

Have you checked the following article?

How To: Get embed token using Get/Post only

The call to generate Access Token should be

"

POST: https://login.microsoftonline.com/common/oauth2/token
data: {
    grant_type: password
    scope: openid
    resource: https://analysis.windows.net/powerbi/api
    client_id: {Client ID}
    username: {PBI Account Username}
    password: {PBI Account Username}
}

--Returns Json:
 
{
    "token_type": "Bearer",
    "scope": "Report.Read.All ...",
    "expires_in": "xxxx",
    "ext_expires_in": "0",
    "expires_on": "xxxxxxxxxx",
    "not_before": "xxxxxxxxxxx",
    "resource": "https://analysis.windows.net/powerbi/api",
    "access_token": "eyJ0eXAi...",
    "refresh_token": "AQABA...",
    "id_token": "eyJ...."
}

"

The resource should be 

https://analysis.windows.net/powerbi/api

Make sure you have specified the other data part correctly.

for the process, please also check the document below:

Step 2: Get n authentication access token

 

Regards,

Michael

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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