<?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: Headless authentication for API calls in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Headless-authentication-for-API-calls/m-p/200131#M6385</link>
    <description>&lt;P&gt;I got my authentication running headless with passing a&amp;nbsp;UserCredential instance to the AuthContext. Therefor I provide username and password. See also:&amp;nbsp;&lt;A href="https://github.com/Microsoft/PowerBI-Developer-Samples/blob/master/App%20Owns%20Data/PowerBIEmbedded_AppOwnsData/Controllers/HomeController.cs" target="_blank"&gt;https://github.com/Microsoft/PowerBI-Developer-Samples/blob/master/App%20Owns%20Data/PowerBIEmbedded_AppOwnsData/Controllers/HomeController.cs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They are using a UserPasswordCredential object, I am not aware of the differences of those two classes. But both should work headless.&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jun 2017 08:03:46 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-06-23T08:03:46Z</dc:date>
    <item>
      <title>Headless authentication for API calls</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Headless-authentication-for-API-calls/m-p/154025#M5209</link>
      <description>&lt;P&gt;We are using the PowerBI API to deploy reports to the PowerBI Service (not embedded). Currently we have written a command line tool that takes a few parameters and performs the import. However, we are not able to use this on our build server or as a service &amp;nbsp;because it requires interactive authentication.&amp;nbsp;We have tried registering and using both native and web apps in the developer portal, but both approaches require and integrated login (pop up) somewhere up the chain. Ideally I would like to run the command line tool with an API Key and Secret, not associated with any user and perform the operations required.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There appear to be a couple&amp;nbsp;of work arounds:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Write a wrapper service (this requires extra infrastructure, hosting, maintenanc etc) - not ideal.&lt;/LI&gt;&lt;LI&gt;Use a user account, log in once interactively and accept the grants and then revert to usernamer and password authentication - like a service account&amp;nbsp;- this seems to be the most appealing.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In short, I'd just like to know if I am missing a trick in setting up headless authentication for the API with an API Key and Secret, is it at all possible? &amp;nbsp;(I always end up with a 403 Forbidden using the web app keys generated on the developer portal).&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;</description>
      <pubDate>Wed, 05 Apr 2017 13:19:09 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Headless-authentication-for-API-calls/m-p/154025#M5209</guid>
      <dc:creator>Murray</dc:creator>
      <dc:date>2017-04-05T13:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Headless authentication for API calls</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Headless-authentication-for-API-calls/m-p/154245#M5215</link>
      <description>&lt;P&gt;I've had the same issue recently and have had to switch to using a device code. I've just dumped a copy of my code below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are a few steps required.&lt;/P&gt;&lt;P&gt;1 - Run it initially to get a device code. You will have to go to a verification url and enter a code. This then authenticates the app.&lt;/P&gt;&lt;P&gt;2 - Serialise the token cache from the authentication token.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next time through, create a token cache from the saved state and you can log back in.&lt;/P&gt;&lt;P&gt;It all feels a bit hacky, but appears to work ok. I'm planning on creating a simple github project with all of this in, but am still debugging some issues at the moment&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;        public PowerBIClient(string clientId, string key, HttpClient httpClient, ILogger log, byte[] state)
        {
            Log = log;
            ClientId = clientId;
            _key = key;
            _httpClient = httpClient;
            var tokenCache = state == null ? new TokenCache() : new TokenCache(state);
            _authenticationContext = new AuthenticationContext(AuthorityUri, tokenCache);
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#pragma warning disable RCS1163 // Unused parameter.
        private async Task&amp;lt;string&amp;gt; GetAccessTokenAsync(CancellationToken ct)
#pragma warning restore RCS1163 // Unused parameter.
        {
            if (_accessToken == null)
            {
                if (_authenticationContext.TokenCache.Count &amp;gt; 0)
                {
                    try
                    {
                        var result = await _authenticationContext.AcquireTokenSilentAsync(ResourceUri, ClientId).ConfigureAwait(false);
                        _accessToken = result.AccessToken;
                        Log.Debug("Got cached access token until {expire} ({duration})",
                            result.ExpiresOn, result.ExpiresOn - DateTimeOffset.UtcNow);
                        return _accessToken;
                    }
                    catch (Exception ex)
                    {
                        Log.Warning("Failed to acquire token from cached {exception}", ex.Message);
                    }
                }
            }

            if (_accessToken == null)
            {
                var codeResult = await _authenticationContext.AcquireDeviceCodeAsync(ResourceUri, ClientId).ConfigureAwait(false);
                Log.Warning("Need authentication from {location} {code}", codeResult.VerificationUrl, codeResult.UserCode);
                var result = await _authenticationContext.AcquireTokenByDeviceCodeAsync(codeResult).ConfigureAwait(false);
                Log.Debug("Got new access token until {expire} ({duration})",
                            result.ExpiresOn, result.ExpiresOn - DateTimeOffset.UtcNow);

                _accessToken = result.AccessToken;
            }
            else
            {
                var result = await _authenticationContext.AcquireTokenSilentAsync(ResourceUri, ClientId).ConfigureAwait(false);
                Log.Debug("Got refreshed access token until {expire} ({duration})",
                            result.ExpiresOn, result.ExpiresOn - DateTimeOffset.UtcNow);
                _accessToken = result.AccessToken;
            }

            return _accessToken;
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 19:03:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Headless-authentication-for-API-calls/m-p/154245#M5215</guid>
      <dc:creator>njrandell</dc:creator>
      <dc:date>2017-04-05T19:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Headless authentication for API calls</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Headless-authentication-for-API-calls/m-p/198854#M6340</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/26151"&gt;@njrandell&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you able to supply some more detail? &amp;nbsp;I probably need some more info to get these functions working.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Phil&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2017 22:04:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Headless-authentication-for-API-calls/m-p/198854#M6340</guid>
      <dc:creator>Phil_Seamark</dc:creator>
      <dc:date>2017-06-21T22:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: Headless authentication for API calls</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Headless-authentication-for-API-calls/m-p/199412#M6358</link>
      <description>&lt;P&gt;Have a look at&amp;nbsp;&lt;A href="https://github.com/sceneskope/powerbi" target="_blank"&gt;https://github.com/sceneskope/powerbi&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Admitedly the documentation isn't great, but I've had this working for the last few months and am happy to make it clearer if needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 12:11:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Headless-authentication-for-API-calls/m-p/199412#M6358</guid>
      <dc:creator>njrandell</dc:creator>
      <dc:date>2017-06-22T12:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Headless authentication for API calls</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Headless-authentication-for-API-calls/m-p/200131#M6385</link>
      <description>&lt;P&gt;I got my authentication running headless with passing a&amp;nbsp;UserCredential instance to the AuthContext. Therefor I provide username and password. See also:&amp;nbsp;&lt;A href="https://github.com/Microsoft/PowerBI-Developer-Samples/blob/master/App%20Owns%20Data/PowerBIEmbedded_AppOwnsData/Controllers/HomeController.cs" target="_blank"&gt;https://github.com/Microsoft/PowerBI-Developer-Samples/blob/master/App%20Owns%20Data/PowerBIEmbedded_AppOwnsData/Controllers/HomeController.cs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They are using a UserPasswordCredential object, I am not aware of the differences of those two classes. But both should work headless.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 08:03:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Headless-authentication-for-API-calls/m-p/200131#M6385</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-06-23T08:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Headless authentication for API calls</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Headless-authentication-for-API-calls/m-p/200133#M6386</link>
      <description>&lt;P&gt;I'm using .Net core, and last time I checked those libraries don't support username and passwords. In fact I remember seeing a comment on github from one of the developers saying they won't add in username and passwords.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the libraries I created on github to push into power bi from a number of places, such as a raspberry pi running a dotnet core app, all the way through to a service fabric service running .net 452.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you aren't using .Net core, then you are ok with the UserPasswordCredential object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 08:08:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Headless-authentication-for-API-calls/m-p/200133#M6386</guid>
      <dc:creator>njrandell</dc:creator>
      <dc:date>2017-06-23T08:08:10Z</dc:date>
    </item>
  </channel>
</rss>

