<?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 OAuth 2.0 Authorization Code flow grant type - Power Query API Connection in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/OAuth-2-0-Authorization-Code-flow-grant-type-Power-Query-API/m-p/1873095#M29697</link>
    <description>&lt;P&gt;Hi, i'm tryng to&amp;nbsp;&lt;SPAN class="Y2IQFc"&gt;to get Access Token from an&amp;nbsp;OAuth2 Authorization Code flow.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Y2IQFc"&gt;Here the code: "PART 1" work fine and return the&amp;nbsp;Authorization Code, bat "PART 2" don't work and return error.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="tw-data-text tw-text-large XcVN5d tw-ta"&gt;&lt;SPAN class="Y2IQFc"&gt;Thanks for help&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;let&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;// PART 1: Get Authorization Code&lt;/FONT&gt;&lt;BR /&gt;Body = &lt;BR /&gt;&lt;FONT color="#FF0000"&gt;"{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;""username"":""&amp;lt;MyUsername&amp;gt;"",&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;""password"":""&amp;lt;MyPsw&amp;gt;"",&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;""scope"":[""&amp;lt;SelectedScope&amp;gt;""]&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;}"&lt;/FONT&gt;,&lt;BR /&gt;&lt;BR /&gt;url = &lt;FONT color="#FF0000"&gt;"http://XXXXXXXXXXXXXXXXXXXXXXXXXXX/api/login/sso"&lt;/FONT&gt;,&lt;BR /&gt;GetJson = Json.Document(Web.Contents(url, [Headers=[ContentType=&lt;FONT color="#FF0000"&gt;"application/json"&lt;/FONT&gt;], Content=Text.ToBinary(Body)])),&lt;BR /&gt;AuthorizationCode = GetJson,&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;// The previous code correctly returns the Authorization Code&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;// PART 2: Now I try to Get Access Token passing the Authorization Code, the client_id and the client_secret&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;// Base64 Encoding&lt;/FONT&gt;&lt;BR /&gt;a = &lt;FONT color="#FF0000"&gt;"&amp;lt;client_id&amp;gt;"&lt;/FONT&gt; &amp;amp; &lt;FONT color="#FF0000"&gt;":"&lt;/FONT&gt; &amp;amp; &lt;FONT color="#FF0000"&gt;"&amp;lt;client_secret&amp;gt;"&lt;/FONT&gt;,&lt;BR /&gt;a2 = Text.ToBinary(a),&lt;BR /&gt;a3 = Binary.ToText(a2, BinaryEncoding.Base64),&lt;BR /&gt;&lt;BR /&gt;TokenURL = &lt;FONT color="#FF0000"&gt;"http://XXXXXXXXXXXXXXXXXXXXXXXXXXX/oauth2/token/"&lt;/FONT&gt;,&lt;BR /&gt;Body2 = &lt;BR /&gt;&lt;FONT color="#FF0000"&gt;"{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;""grant_type"": ""authorization_code"",&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;""code"": """&lt;FONT color="#000000"&gt;&amp;amp;AuthorizationCode&amp;amp;&lt;/FONT&gt;""" &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;}"&lt;/FONT&gt;,&lt;BR /&gt;&lt;BR /&gt;Source = Web.Contents(TokenURL, [Headers = [ContentType=&lt;FONT color="#FF0000"&gt;"application/json"&lt;/FONT&gt;, Authorization = &lt;FONT color="#FF0000"&gt;"Basic "&lt;/FONT&gt;&amp;amp;a3&amp;amp;&lt;FONT color="#FF0000"&gt;""&lt;/FONT&gt;], Content = Text.ToBinary(Body2)])&lt;BR /&gt;&lt;BR /&gt;in Source&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 31 May 2021 13:28:00 GMT</pubDate>
    <dc:creator>Marco_Iac</dc:creator>
    <dc:date>2021-05-31T13:28:00Z</dc:date>
    <item>
      <title>OAuth 2.0 Authorization Code flow grant type - Power Query API Connection</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/OAuth-2-0-Authorization-Code-flow-grant-type-Power-Query-API/m-p/1873095#M29697</link>
      <description>&lt;P&gt;Hi, i'm tryng to&amp;nbsp;&lt;SPAN class="Y2IQFc"&gt;to get Access Token from an&amp;nbsp;OAuth2 Authorization Code flow.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Y2IQFc"&gt;Here the code: "PART 1" work fine and return the&amp;nbsp;Authorization Code, bat "PART 2" don't work and return error.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="tw-data-text tw-text-large XcVN5d tw-ta"&gt;&lt;SPAN class="Y2IQFc"&gt;Thanks for help&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;let&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;// PART 1: Get Authorization Code&lt;/FONT&gt;&lt;BR /&gt;Body = &lt;BR /&gt;&lt;FONT color="#FF0000"&gt;"{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;""username"":""&amp;lt;MyUsername&amp;gt;"",&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;""password"":""&amp;lt;MyPsw&amp;gt;"",&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;""scope"":[""&amp;lt;SelectedScope&amp;gt;""]&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;}"&lt;/FONT&gt;,&lt;BR /&gt;&lt;BR /&gt;url = &lt;FONT color="#FF0000"&gt;"http://XXXXXXXXXXXXXXXXXXXXXXXXXXX/api/login/sso"&lt;/FONT&gt;,&lt;BR /&gt;GetJson = Json.Document(Web.Contents(url, [Headers=[ContentType=&lt;FONT color="#FF0000"&gt;"application/json"&lt;/FONT&gt;], Content=Text.ToBinary(Body)])),&lt;BR /&gt;AuthorizationCode = GetJson,&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;// The previous code correctly returns the Authorization Code&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;// PART 2: Now I try to Get Access Token passing the Authorization Code, the client_id and the client_secret&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;// Base64 Encoding&lt;/FONT&gt;&lt;BR /&gt;a = &lt;FONT color="#FF0000"&gt;"&amp;lt;client_id&amp;gt;"&lt;/FONT&gt; &amp;amp; &lt;FONT color="#FF0000"&gt;":"&lt;/FONT&gt; &amp;amp; &lt;FONT color="#FF0000"&gt;"&amp;lt;client_secret&amp;gt;"&lt;/FONT&gt;,&lt;BR /&gt;a2 = Text.ToBinary(a),&lt;BR /&gt;a3 = Binary.ToText(a2, BinaryEncoding.Base64),&lt;BR /&gt;&lt;BR /&gt;TokenURL = &lt;FONT color="#FF0000"&gt;"http://XXXXXXXXXXXXXXXXXXXXXXXXXXX/oauth2/token/"&lt;/FONT&gt;,&lt;BR /&gt;Body2 = &lt;BR /&gt;&lt;FONT color="#FF0000"&gt;"{&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;""grant_type"": ""authorization_code"",&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;""code"": """&lt;FONT color="#000000"&gt;&amp;amp;AuthorizationCode&amp;amp;&lt;/FONT&gt;""" &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;}"&lt;/FONT&gt;,&lt;BR /&gt;&lt;BR /&gt;Source = Web.Contents(TokenURL, [Headers = [ContentType=&lt;FONT color="#FF0000"&gt;"application/json"&lt;/FONT&gt;, Authorization = &lt;FONT color="#FF0000"&gt;"Basic "&lt;/FONT&gt;&amp;amp;a3&amp;amp;&lt;FONT color="#FF0000"&gt;""&lt;/FONT&gt;], Content = Text.ToBinary(Body2)])&lt;BR /&gt;&lt;BR /&gt;in Source&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 May 2021 13:28:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/OAuth-2-0-Authorization-Code-flow-grant-type-Power-Query-API/m-p/1873095#M29697</guid>
      <dc:creator>Marco_Iac</dc:creator>
      <dc:date>2021-05-31T13:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: OAuth 2.0 Authorization Code flow grant type - Power Query API Connection</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/OAuth-2-0-Authorization-Code-flow-grant-type-Power-Query-API/m-p/1876396#M29724</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/190146"&gt;@Marco_Iac&lt;/a&gt;,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;What type of error message displayed? Can you please share more detailed information?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;&lt;A href="http://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490" target="_blank"&gt;How to Get Your Question Answered Quickly&amp;nbsp;&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;In addition, you can also try to add the 'relative path' option to your connector if it works:&lt;/FONT&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    // PART 1: Get Authorization Code
    Body =
        "{'username':'&amp;lt;MyUsername&amp;gt;','password':'&amp;lt;MyPsw&amp;gt;','scope':['&amp;lt;SelectedScope&amp;gt;']}",
    url = "http://XXXXXXXXXXXXXXXXXXXXXXXXXXX/api/login/sso",
    GetJson =
        Json.Document(
            Web.Contents(
                url,
                [
                    Headers = [
                        ContentType = "application/json"
                    ],
                    Content = Text.ToBinary(Body)
                ]
            )
        ),
    AuthorizationCode = GetJson,
    // The previous code correctly returns the Authorization Code
    // PART 2: Now I try to Get Access Token passing the Authorization Code, the client_id and the client_secret
    // Base64 Encoding
    _client = "&amp;lt;client_id&amp;gt;:&amp;lt;client_secret&amp;gt;",
    TokenURL = "http://XXXXXXXX.XXXXXXXXXXX.com",
    Body2 =
        "{'grant_type': 'authorization_code','code': '"&amp;amp; AuthorizationCode&amp;amp; '" }",
    Source =
        Web.Contents(
            TokenURL,
            [
                Headers = [
                    ContentType = "application/json",
                    Authorization = "Basic " &amp;amp; Binary.ToText(Text.ToBinary(_client), BinaryEncoding.Base64)
                ],
                RelativePath="/oauth2/token/",
                Content = Text.ToBinary(Body2)
            ]
        )
in
    Source&lt;/LI-CODE&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;&lt;A href="https://blog.crossjoin.co.uk/2016/08/16/using-the-relativepath-and-query-options-with-web-contents-in-power-query-and-power-bi-m-code/" target="_blank"&gt;Chris Webb's BI Blog: Using The RelativePath And Query Options With Web.Contents() In Power Query And Power BI M Code Chris Webb's BI Blog (crossjoin.co.uk)&lt;/A&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Regards,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="tahoma,arial,helvetica,sans-serif"&gt;Xiaoxin Sheng&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jun 2021 02:18:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/OAuth-2-0-Authorization-Code-flow-grant-type-Power-Query-API/m-p/1876396#M29724</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-06-02T02:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: OAuth 2.0 Authorization Code flow grant type - Power Query API Connection</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/OAuth-2-0-Authorization-Code-flow-grant-type-Power-Query-API/m-p/1879330#M29759</link>
      <description>&lt;P&gt;&lt;SPAN class="Y2IQFc"&gt;Solved, the problem was due to an erroneous Base64 Encoding&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jun 2021 06:21:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/OAuth-2-0-Authorization-Code-flow-grant-type-Power-Query-API/m-p/1879330#M29759</guid>
      <dc:creator>Marco_Iac</dc:creator>
      <dc:date>2021-06-03T06:21:42Z</dc:date>
    </item>
  </channel>
</rss>

