Forum Discussion

SarahQUL's avatar
SarahQUL
Frequent Visitor
9 years ago
Solved

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, b...
  • Eric_Zhang's avatar
    9 years ago

    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
        }
    }