<?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 Re: AccessUnauthorized on Mashup engine using Gateways - Update Datasource API in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/AccessUnauthorized-on-Mashup-engine-using-Gateways-Update/m-p/2170324#M32722</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/182446"&gt;@V-lianl-msft&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;thank you for your reply but your suggessted method definitively doesn't work for many reasons:&lt;/P&gt;&lt;P&gt;1. The appid has not the correct scope&lt;/P&gt;&lt;P&gt;2. The application is not consented by the user (this one you can fix but the 1 not&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here the issue is another:&lt;/P&gt;&lt;P&gt;the API described here&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#basic-credentials-example" target="_blank"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource&lt;/A&gt;&lt;/P&gt;&lt;P&gt;for the OAUTH2 credentials (the unique valid for datasource of type dataflow) requires a token in the payload and a token in the authorization header.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The token in the authorization header I think I provided it correctly in fact the first authorization layer of the API succeed and I can call also other APIs with the same token.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue is in the token in the payload, I'm not able to make it succeed with any token I provide except a token generated using interactive login (i.e. copy/paste the token from the power bi portal with the user logged in), in all the other cases (token generated programmatically using password grant) I always end up with an internal error coming from the Mash-up engine (this is an additional proof that the API authorization pass correctly but is the backend that does not accept the token I pass in the payload).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also compared with jwt.io the 2 tokens (the one that works coming from the portal and the one generated programmatically and the unique differnce i found is the scope. In the portal is user_impersonation, programmatically is Dataset.ReadWrite.All and all the other API permissions). The problem is that I will never be able to generate programmatically a token with scope user_impersonation or I do not know how to make it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In conclusion: how to generate a token that is valid in the PAYLOAD of this API?&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#oauth2-credentials-example" target="_blank"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#oauth2-credentials-example&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Nov 2021 09:52:11 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-11-03T09:52:11Z</dc:date>
    <item>
      <title>AccessUnauthorized on Mashup engine using Gateways - Update Datasource API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/AccessUnauthorized-on-Mashup-engine-using-Gateways-Update/m-p/2158106#M32624</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm using the&amp;nbsp;Gateways - Update Datasource API to programmatically change the credentials of a dataset that connects to a PBI dataflow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use the following call:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PATCH https://api.powerbi.com/v1.0/myorg/gateways/fb6ff.../datasources/f580...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the following payload:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "credentialDetails": {
    "credentialType": "OAuth2",
    "credentials": "{\"credentialData\":[{\"name\":\"accessToken\", \"value\":\"eyJ0...\"}]}",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "None"
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here my discoveries:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. The API goes in error if in the Bearer I use a SP token. I must use a user token obtained via OAUTH2 password grant if I want the API to succeed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. I'm unable to let the API succeed if I use the user password grant token in the payload or the SP token. The unique way to make it functioning is using a token obtained via interactive authentication.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any clue how to make it works in the above scenario?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here the results I obtain:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;API call using a SP in the Authorization header (regardless of what token I use in the payload):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "error": {
    "code": "PowerBINotAuthorizedException",
    "pbi.error": {
      "code": "PowerBINotAuthorizedException",
      "parameters": {},
      "details": [],
      "exceptionCulprit": 1
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;API call using a password grant token in the Authorization Bearer and in the payoad:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "error": {
    "code": "DM_GWPipeline_Gateway_InvalidConnectionCredentials",
    "pbi.error": {
      "code": "DM_GWPipeline_Gateway_InvalidConnectionCredentials",
      "parameters": {},
      "details": [
        {
          "code": "DM_ErrorDetailNameCode_UnderlyingErrorCode",
          "detail": {
            "type": 1,
            "value": "-2147467259"
          }
        },
        {
          "code": "DM_ErrorDetailNameCode_UnderlyingErrorMessage",
          "detail": {
            "type": 1,
            "value": "The credentials provided for the PowerBI source are invalid. (Source at PowerBI.)"
          }
        },
        {
          "code": "DM_ErrorDetailNameCode_UnderlyingHResult",
          "detail": {
            "type": 1,
            "value": "-2147467259"
          }
        },
        {
          "code": "Microsoft.Data.Mashup.CredentialError.DataSourceKind",
          "detail": {
            "type": 1,
            "value": "PowerBI"
          }
        },
        {
          "code": "Microsoft.Data.Mashup.CredentialError.DataSourceOriginKind",
          "detail": {
            "type": 1,
            "value": "Web"
          }
        },
        {
          "code": "Microsoft.Data.Mashup.CredentialError.DataSourceOriginPath",
          "detail": {
            "type": 1,
            "value": "https://wabi-north-europe-k-primary-redirect.analysis.windows.net/metadata/v201606/cdsa/workspaces"
          }
        },
        {
          "code": "Microsoft.Data.Mashup.CredentialError.DataSourcePath",
          "detail": {
            "type": 1,
            "value": "PowerBI"
          }
        },
        {
          "code": "Microsoft.Data.Mashup.CredentialError.Reason",
          "detail": {
            "type": 1,
            "value": "AccessUnauthorized"
          }
        },
        {
          "code": "Microsoft.Data.Mashup.MashupSecurityException.DataSources",
          "detail": {
            "type": 1,
            "value": "[{\"kind\":\"PowerBI\",\"path\":\"PowerBI\"}]"
          }
        },
        {
          "code": "Microsoft.Data.Mashup.MashupSecurityException.Reason",
          "detail": {
            "type": 1,
            "value": "AccessUnauthorized"
          }
        }
      ],
      "exceptionCulprit": 1
    }
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;API call using&amp;nbsp;a password grant token in the Authorization Bearer and an interactive user token in the payload (same user as of the password grant token but obtained interactively) :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;200 OK&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any clue? Obviously I need to obtain the token programmatically I cannot obtain it interactively since I'm working an an CI/CD powershell script.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 11:36:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/AccessUnauthorized-on-Mashup-engine-using-Gateways-Update/m-p/2158106#M32624</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-10-27T11:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: AccessUnauthorized on Mashup engine using Gateways - Update Datasource API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/AccessUnauthorized-on-Mashup-engine-using-Gateways-Update/m-p/2165740#M32689</link>
      <description>&lt;P&gt;Hi @Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could try&amp;nbsp;&lt;STRONG&gt;&lt;A href="https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth-ropc#authorization-request" target="_self"&gt;OAuth 2.0 resource owner password credentials grant&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;// Line breaks and spaces are for legibility only.  This is a public client, so no secret is required.

POST {tenant}/oauth2/v2.0/token
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded

client_id=6731de76-14a6-49ae-97bc-6eba6914391e
&amp;amp;scope=user.read%20openid%20profile%20offline_access
&amp;amp;username=MyUsername@myTenant.com
&amp;amp;password=SuperS3cret
&amp;amp;grant_type=password&lt;/LI-CODE&gt;
&lt;P&gt;&lt;SPAN&gt;Make sure your Application's&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Grant Types&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;include&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Password.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;You can also refer to:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/63321532/sharepoint-rest-api-how-to-get-access-token" target="_self"&gt;https://stackoverflow.com/questions/63321532/sharepoint-rest-api-how-to-get-access-token&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Liang&lt;BR /&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Nov 2021 08:09:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/AccessUnauthorized-on-Mashup-engine-using-Gateways-Update/m-p/2165740#M32689</guid>
      <dc:creator>V-lianl-msft</dc:creator>
      <dc:date>2021-11-01T08:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: AccessUnauthorized on Mashup engine using Gateways - Update Datasource API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/AccessUnauthorized-on-Mashup-engine-using-Gateways-Update/m-p/2170324#M32722</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/182446"&gt;@V-lianl-msft&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;thank you for your reply but your suggessted method definitively doesn't work for many reasons:&lt;/P&gt;&lt;P&gt;1. The appid has not the correct scope&lt;/P&gt;&lt;P&gt;2. The application is not consented by the user (this one you can fix but the 1 not&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here the issue is another:&lt;/P&gt;&lt;P&gt;the API described here&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#basic-credentials-example" target="_blank"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource&lt;/A&gt;&lt;/P&gt;&lt;P&gt;for the OAUTH2 credentials (the unique valid for datasource of type dataflow) requires a token in the payload and a token in the authorization header.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The token in the authorization header I think I provided it correctly in fact the first authorization layer of the API succeed and I can call also other APIs with the same token.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue is in the token in the payload, I'm not able to make it succeed with any token I provide except a token generated using interactive login (i.e. copy/paste the token from the power bi portal with the user logged in), in all the other cases (token generated programmatically using password grant) I always end up with an internal error coming from the Mash-up engine (this is an additional proof that the API authorization pass correctly but is the backend that does not accept the token I pass in the payload).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also compared with jwt.io the 2 tokens (the one that works coming from the portal and the one generated programmatically and the unique differnce i found is the scope. In the portal is user_impersonation, programmatically is Dataset.ReadWrite.All and all the other API permissions). The problem is that I will never be able to generate programmatically a token with scope user_impersonation or I do not know how to make it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In conclusion: how to generate a token that is valid in the PAYLOAD of this API?&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#oauth2-credentials-example" target="_blank"&gt;https://docs.microsoft.com/en-us/rest/api/power-bi/gateways/update-datasource#oauth2-credentials-example&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Nov 2021 09:52:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/AccessUnauthorized-on-Mashup-engine-using-Gateways-Update/m-p/2170324#M32722</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-11-03T09:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: AccessUnauthorized on Mashup engine using Gateways - Update Datasource API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/AccessUnauthorized-on-Mashup-engine-using-Gateways-Update/m-p/2230095#M33365</link>
      <description>&lt;P&gt;Finally got an answer from the PBI product group.&lt;/P&gt;&lt;P&gt;The correct payload to use (totally undocumented) is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "credentialDetails": {
    "credentialType": "OAuth2",
    "encryptedConnection": "Encrypted",
    "encryptionAlgorithm": "None",
    "privacyLevel": "Organizational",
    "useCallerAADIdentity": true
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I call it &lt;SPAN&gt;using a password grant token in the Authorization Bearer.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This undocumented payload does not require a token in the payload thanks to the property:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;"useCallerAADIdentity": true&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Dec 2021 11:01:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/AccessUnauthorized-on-Mashup-engine-using-Gateways-Update/m-p/2230095#M33365</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-12-09T11:01:41Z</dc:date>
    </item>
  </channel>
</rss>

