Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

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.


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?

  • 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

1 Reply

  • v-micsh-msft's avatar
    v-micsh-msft
    Microsoft 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