Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
SarahQUL
Frequent Visitor

Problem: I can't have an Access Token

Hello, I have a problem, with your explication on your API : "https://powerbi.microsoft.com/fr-fr/documentation/powerbi-developer-walkthrough-push-data-get-token/"

 

I can't have an Access Token, because I have meet two problems with you explication.

  1. I can't install the package "Microsoft.IdentityModel.Clients.ActiveDirectory" with the version "2.21.301221612", because when I try to install this package, the console tell me:  some of the package s that will be installed are incompatible with " .NetCoreApp, version = v1.1". But I can install the last version 3.13.9. I have search on your API, the Forums, and the Internet an explication but I haven't found any informations. I would like some explication and perhaps a solution.
  2. When I retrieve the Code on your page for "Visual Studio" , a can't use the methode:  " String token = authContext.AcquireToken(ressourceUri, ClientID, newUri(redirectUri)).AccessToken;  "
    I suppose this is a problem with the version of the package I have install, but when I go on the API in order to found an other solution, I realise the documentation haven't the last version on the methods. The API are with the version 2.19.208020213. And I found the information are not very details. I don't found the help I search.

 

I'm waiting for you answer, 

 

Sarah Q.

1 ACCEPTED SOLUTION
Eric_Zhang
Employee
Employee


@SarahQUL wrote:

Hello, I have a problem, with your explication on your API : "https://powerbi.microsoft.com/fr-fr/documentation/powerbi-developer-walkthrough-push-data-get-token/"

 

I can't have an Access Token, because I have meet two problems with you explication.

  1. I can't install the package "Microsoft.IdentityModel.Clients.ActiveDirectory" with the version "2.21.301221612", because when I try to install this package, the console tell me:  some of the package s that will be installed are incompatible with " .NetCoreApp, version = v1.1". But I can install the last version 3.13.9. I have search on your API, the Forums, and the Internet an explication but I haven't found any informations. I would like some explication and perhaps a solution.
  2. When I retrieve the Code on your page for "Visual Studio" , a can't use the methode:  " String token = authContext.AcquireToken(ressourceUri, ClientID, newUri(redirectUri)).AccessToken;  "
    I suppose this is a problem with the version of the package I have install, but when I go on the API in order to found an other solution, I realise the documentation haven't the last version on the methods. The API are with the version 2.19.208020213. And I found the information are not very details. I don't found the help I search.

 

I'm waiting for you answer, 

 

Sarah Q.


To get a token with the ADAL 3.13.9, try

 

using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication32
{
    class Program
    {
        static void Main(string[] args)
        {
            string token = GetToken();
            Console.WriteLine(token);
            Console.ReadLine();

        }

        #region Get an authentication access token
        private static string GetToken()
        {  
            //The client id that Azure AD created when you registered your client app.
            string clientID = "d9146xxxxxx946e8";

            //RedirectUri you used when you register your app.
            //For a client app, a redirect uri gives Azure AD more details on the application that it will authenticate.
            // You can use this redirect uri for your client app
            string redirectUri = "https://login.live.com/oauth20_desktop.srf";

            //Resource Uri for Power BI API
            string resourceUri = "https://analysis.windows.net/powerbi/api";

            //OAuth2 authority Uri
            string authorityUri = "https://login.windows.net/common/oauth2/authorize";
 
            // Call AcquireToken to get an Azure token from Azure Active Directory token issuance endpoint
            AuthenticationContext authContext = new AuthenticationContext(authorityUri);

            //string token = authContext.AcquireToken(resourceUri, clientID, new Uri(redirectUri)).AccessToken;

            return authContext.AcquireTokenAsync(resourceUri, clientID, new Uri(redirectUri), new PlatformParameters(0)).Result.AccessToken;
             

        }

        #endregion
    }
}

View solution in original post

4 REPLIES 4
Eric_Zhang
Employee
Employee


@SarahQUL wrote:

Hello, I have a problem, with your explication on your API : "https://powerbi.microsoft.com/fr-fr/documentation/powerbi-developer-walkthrough-push-data-get-token/"

 

I can't have an Access Token, because I have meet two problems with you explication.

  1. I can't install the package "Microsoft.IdentityModel.Clients.ActiveDirectory" with the version "2.21.301221612", because when I try to install this package, the console tell me:  some of the package s that will be installed are incompatible with " .NetCoreApp, version = v1.1". But I can install the last version 3.13.9. I have search on your API, the Forums, and the Internet an explication but I haven't found any informations. I would like some explication and perhaps a solution.
  2. When I retrieve the Code on your page for "Visual Studio" , a can't use the methode:  " String token = authContext.AcquireToken(ressourceUri, ClientID, newUri(redirectUri)).AccessToken;  "
    I suppose this is a problem with the version of the package I have install, but when I go on the API in order to found an other solution, I realise the documentation haven't the last version on the methods. The API are with the version 2.19.208020213. And I found the information are not very details. I don't found the help I search.

 

I'm waiting for you answer, 

 

Sarah Q.


To get a token with the ADAL 3.13.9, try

 

using Microsoft.IdentityModel.Clients.ActiveDirectory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication32
{
    class Program
    {
        static void Main(string[] args)
        {
            string token = GetToken();
            Console.WriteLine(token);
            Console.ReadLine();

        }

        #region Get an authentication access token
        private static string GetToken()
        {  
            //The client id that Azure AD created when you registered your client app.
            string clientID = "d9146xxxxxx946e8";

            //RedirectUri you used when you register your app.
            //For a client app, a redirect uri gives Azure AD more details on the application that it will authenticate.
            // You can use this redirect uri for your client app
            string redirectUri = "https://login.live.com/oauth20_desktop.srf";

            //Resource Uri for Power BI API
            string resourceUri = "https://analysis.windows.net/powerbi/api";

            //OAuth2 authority Uri
            string authorityUri = "https://login.windows.net/common/oauth2/authorize";
 
            // Call AcquireToken to get an Azure token from Azure Active Directory token issuance endpoint
            AuthenticationContext authContext = new AuthenticationContext(authorityUri);

            //string token = authContext.AcquireToken(resourceUri, clientID, new Uri(redirectUri)).AccessToken;

            return authContext.AcquireTokenAsync(resourceUri, clientID, new Uri(redirectUri), new PlatformParameters(0)).Result.AccessToken;
             

        }

        #endregion
    }
}

Every time I run my C# code to retrieve an access token. A modal dialog box pops up to enter logon credentials. I check the save credentials box, but every call is the same thing. How can you automate smething that pops up a modal dialog? 

I recieve the token ok, but can I reuse that same token so the testing is not so aggrevating and time consuming? 

Please help... 

Thanks 

Paul

Excuse me Eric, I try to implement your solution, But I have a new problem.

 

When I test your code I have a " System.AggregateException : 'One or mor errors occured' " that appeared.

 

But I don't know the C# and I can't solve this exception, Have you a solution at this exception?

 

 

Thank's for you response, when I can test your purpose ( I'm in Holliday's), I can validite or ask you some informations.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.