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