<?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: Authenticating with C# API V2 against Azure Power BI Workspaces in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Authenticating-with-C-API-V2-against-Azure-Power-BI-Workspaces/m-p/255321#M7880</link>
    <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/15380"&gt;@IanV&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The Power BI Embedded workspace collection is being deprecated. The new replacement is&amp;nbsp;&lt;A href="https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-embedding/#embedding-with-non-power-bi-users-app-owns-data" target="_self"&gt;Embedding with non-Power BI users (app owns data)&lt;/A&gt;. The correlated github demo is&amp;nbsp;&lt;A href="https://github.com/Microsoft/PowerBI-Developer-Samples/tree/master/App%20Owns%20Data" target="_self"&gt;App Owns Data&lt;/A&gt;. See authentication code snippet below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;// Create a user password cradentials.
            var credential = new UserPasswordCredential(Username, Password);

            // Authenticate using created credentials
            var authenticationContext = new AuthenticationContext(AuthorityUrl);
            var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);

            if (authenticationResult == null)
            {
                return View(new EmbedConfig()
                {
                    ErrorMessage = "Authentication Failed."
                });
            }

            var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");&lt;/PRE&gt;
&lt;P&gt;The username and password are of one Power BI Pro account. The client_id is from a registered Azure AD application. See this &lt;A href="https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-embedding-content/" target="_self"&gt;tutorial&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Sep 2017 06:02:55 GMT</pubDate>
    <dc:creator>Eric_Zhang</dc:creator>
    <dc:date>2017-09-20T06:02:55Z</dc:date>
    <item>
      <title>Authenticating with C# API V2 against Azure Power BI Workspaces</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Authenticating-with-C-API-V2-against-Azure-Power-BI-Workspaces/m-p/254956#M7867</link>
      <description>&lt;P&gt;The new Power BI API under the&amp;nbsp;Microsoft.PowerBI.Api.V2 namespace has some additional functionality that I'd like to leverage, but I can't seem to get it to authenticate for the life of me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an example of how I created a client&amp;nbsp;with V1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;var apiEndpoint = new Uri("https://api.powerbi.com");
var accessKey = "thisvalueisprovidedbyazure";

var credentials = new TokenCredentials(accessKey, "AppKey");
var clientV1 = new Microsoft.PowerBI.Api.V1.PowerBIClient(apiEndpoint, credentials);&lt;/PRE&gt;&lt;P&gt;As implied by the fake value, that access key is provided by Azure, as you can see in "Get started with Microsoft Power BI Embedded" article here:&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/azure/power-bi-embedded/power-bi-embedded-get-started" target="_blank"&gt;https://docs.microsoft.com/en-us/azure/power-bi-embedded/power-bi-embedded-get-started&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could then use it with a workspaceId and collectionName (also created in Azure):&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;var collectionName  = "my-power-bi-collection";
var workspaceId = "00000000-0000-0000-0000-000000000000";

var datasets = await client.Datasets.GetDatasetsAsync(collectionName, workspaceId);&lt;/PRE&gt;&lt;P&gt;The new API seems to be completely different, however. I tried following &lt;A href="https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-get-azuread-access-token/" target="_self"&gt;the example in this article&lt;/A&gt; and the one in the&amp;nbsp;&lt;A href="https://github.com/Microsoft/PowerBI-CSharp" target="_self"&gt;git repository readme file&lt;/A&gt;, but it wasn't very clear where some of these values are coming from. They seem geared toward generating an access token via username/password or AD.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the example from github, it's not very clear what some of these values are. For example, what is the ClientId? Why is the AuthorityUrl pointing to "&lt;SPAN&gt;&lt;A href="https://login.windows.net/common/oauth2/authorize/" target="_blank"&gt;https://login.windows.net/common/oauth2/authorize/&lt;/A&gt;"? Is that required for Azure? There is also no mention of workspaces (they seem to have been replaced by groups?)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rather than generating a new token, I tried using the token&amp;nbsp;provided by Azure, and it gives me a 403 FORBIDDEN every time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know what is required to get the new API running against Azure Power BI workspaces?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Sep 2017 16:37:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Authenticating-with-C-API-V2-against-Azure-Power-BI-Workspaces/m-p/254956#M7867</guid>
      <dc:creator>IanV</dc:creator>
      <dc:date>2017-09-19T16:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Authenticating with C# API V2 against Azure Power BI Workspaces</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Authenticating-with-C-API-V2-against-Azure-Power-BI-Workspaces/m-p/255321#M7880</link>
      <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/15380"&gt;@IanV&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;The Power BI Embedded workspace collection is being deprecated. The new replacement is&amp;nbsp;&lt;A href="https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-embedding/#embedding-with-non-power-bi-users-app-owns-data" target="_self"&gt;Embedding with non-Power BI users (app owns data)&lt;/A&gt;. The correlated github demo is&amp;nbsp;&lt;A href="https://github.com/Microsoft/PowerBI-Developer-Samples/tree/master/App%20Owns%20Data" target="_self"&gt;App Owns Data&lt;/A&gt;. See authentication code snippet below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;// Create a user password cradentials.
            var credential = new UserPasswordCredential(Username, Password);

            // Authenticate using created credentials
            var authenticationContext = new AuthenticationContext(AuthorityUrl);
            var authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);

            if (authenticationResult == null)
            {
                return View(new EmbedConfig()
                {
                    ErrorMessage = "Authentication Failed."
                });
            }

            var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");&lt;/PRE&gt;
&lt;P&gt;The username and password are of one Power BI Pro account. The client_id is from a registered Azure AD application. See this &lt;A href="https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-embedding-content/" target="_self"&gt;tutorial&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2017 06:02:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Authenticating-with-C-API-V2-against-Azure-Power-BI-Workspaces/m-p/255321#M7880</guid>
      <dc:creator>Eric_Zhang</dc:creator>
      <dc:date>2017-09-20T06:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: Authenticating with C# API V2 against Azure Power BI Workspaces</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Authenticating-with-C-API-V2-against-Azure-Power-BI-Workspaces/m-p/258509#M7980</link>
      <description>&lt;P&gt;Thanks, I didn't realize that v2 of the API was completely incompatible with the original workspaces. I'll go ahead and give the new way a try.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;P&gt;The Power BI Embedded workspace collection is being deprecated.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;That's what I was afraid of. Do you know how long the existing Azure workspaces will be available and how long they'll be accessible vai API v1?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Sep 2017 13:23:03 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Authenticating-with-C-API-V2-against-Azure-Power-BI-Workspaces/m-p/258509#M7980</guid>
      <dc:creator>IanV</dc:creator>
      <dc:date>2017-09-25T13:23:03Z</dc:date>
    </item>
  </channel>
</rss>

