<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Right way to get Embedded Token in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Right-way-to-get-Embedded-Token/m-p/1120242#M23870</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Today i'm using this code in PHP to get a Embedded Token each time that i need view the reports.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;$client = new \GuzzleHttp\Client();
        $url = 'https://login.windows.net/' . $directoryIdAzure . '/oauth2/token';
        try {
            /** @var GuzzleHttp\Client $client **/
            $response = $client-&amp;gt;post(
               
                $url,
                [
                    "headers" =&amp;gt; [
                        "Accept" =&amp;gt; "application/json"
                    ],
                    'form_params' =&amp;gt; [
                        'resource'      =&amp;gt; 'https://analysis.windows.net/powerbi/api',
                        'client_id'     =&amp;gt; $clientIdAzure,
                        'client_secret' =&amp;gt; $clientSecretAzure,
                        'grant_type'    =&amp;gt; 'password',
                        'username'      =&amp;gt; $userPowerBI,
                        'password'      =&amp;gt; $passPowerBI,
                        'scope'         =&amp;gt; 'openid',
                    ]
                ]
            );

            $body = json_decode($response-&amp;gt;getBody()-&amp;gt;getContents(), true);
            //GET THE TOKEN
            $token = $body['access_token'];&lt;/LI-CODE&gt;&lt;P&gt;It's work but, i don't know if this is right way to get the token, because at Azure Portal show me many logins each time that token Generated..&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="login.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/282555iF78F94AB1E095490/image-size/large?v=v2&amp;amp;px=999" role="button" title="login.png" alt="login.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;i'm lookin for this API:&amp;nbsp;&lt;A href="https://api.powerbi.com/v1.0/myorg/GenerateToken" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/GenerateToken&lt;/A&gt; but i don't know use this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Wich is the right way to generate the Token?&lt;/P&gt;</description>
    <pubDate>Tue, 26 May 2020 12:37:55 GMT</pubDate>
    <dc:creator>marcio_fornari</dc:creator>
    <dc:date>2020-05-26T12:37:55Z</dc:date>
    <item>
      <title>Right way to get Embedded Token</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Right-way-to-get-Embedded-Token/m-p/1120242#M23870</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Today i'm using this code in PHP to get a Embedded Token each time that i need view the reports.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="php"&gt;$client = new \GuzzleHttp\Client();
        $url = 'https://login.windows.net/' . $directoryIdAzure . '/oauth2/token';
        try {
            /** @var GuzzleHttp\Client $client **/
            $response = $client-&amp;gt;post(
               
                $url,
                [
                    "headers" =&amp;gt; [
                        "Accept" =&amp;gt; "application/json"
                    ],
                    'form_params' =&amp;gt; [
                        'resource'      =&amp;gt; 'https://analysis.windows.net/powerbi/api',
                        'client_id'     =&amp;gt; $clientIdAzure,
                        'client_secret' =&amp;gt; $clientSecretAzure,
                        'grant_type'    =&amp;gt; 'password',
                        'username'      =&amp;gt; $userPowerBI,
                        'password'      =&amp;gt; $passPowerBI,
                        'scope'         =&amp;gt; 'openid',
                    ]
                ]
            );

            $body = json_decode($response-&amp;gt;getBody()-&amp;gt;getContents(), true);
            //GET THE TOKEN
            $token = $body['access_token'];&lt;/LI-CODE&gt;&lt;P&gt;It's work but, i don't know if this is right way to get the token, because at Azure Portal show me many logins each time that token Generated..&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="login.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/282555iF78F94AB1E095490/image-size/large?v=v2&amp;amp;px=999" role="button" title="login.png" alt="login.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;i'm lookin for this API:&amp;nbsp;&lt;A href="https://api.powerbi.com/v1.0/myorg/GenerateToken" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/GenerateToken&lt;/A&gt; but i don't know use this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Wich is the right way to generate the Token?&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 12:37:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Right-way-to-get-Embedded-Token/m-p/1120242#M23870</guid>
      <dc:creator>marcio_fornari</dc:creator>
      <dc:date>2020-05-26T12:37:55Z</dc:date>
    </item>
    <item>
      <title>Re: Right way to get Embedded Token</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Right-way-to-get-Embedded-Token/m-p/1121546#M23887</link>
      <description>&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;HI&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/197418"&gt;@marcio_fornari&lt;/a&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;I think these should more relate to your website design, power bi embedded token has its own expiration time. (stored in expiration field)&amp;nbsp; &lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/embedtoken/generatetoken#embedtoken" target="_self"&gt;Embed Token - Generate Token#embedtoken&lt;/A&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;You did not need to invoke generate token API every time you access these contents. BTW, your functions also triggered if web page refreshed or other functions which include multiple threads processing.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;I'd like to suggest you create a function to invoke get token api and save token string and expiration date time to session. It should contain if statement to check the session if the token exists or expired to generate a new token or return current token.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Xiaoxin Sheng&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 07:06:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Right-way-to-get-Embedded-Token/m-p/1121546#M23887</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-05-27T07:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: Right way to get Embedded Token</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Right-way-to-get-Embedded-Token/m-p/1122230#M23893</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;, it's a good ideia save the Token and the Expiration time.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 11:04:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Right-way-to-get-Embedded-Token/m-p/1122230#M23893</guid>
      <dc:creator>marcio_fornari</dc:creator>
      <dc:date>2020-05-27T11:04:40Z</dc:date>
    </item>
  </channel>
</rss>

