none
AcquireToken in AuthenticationContext not working during REST api call RRS feed

  • Question

  • I want to make an REST Api call to the PowerBI REST Api with a C# Script Component within SSIS 2012. To do this i need to aquire a token (according to: https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-authenticate-a-client-app/) . My code to do this looks like this:

    string resourceUri = "https://analysis.windows.net/powerbi/api";        
    string clientId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
    string redirectUri = "https://oauth.powerbi.com/BI";
    
    string authorityUri = "https://login.windows.net/common/oauth2/authorize";
    AuthenticationContext authContext = new AuthenticationContext(authorityUri);
    
    string token = authContext.AcquireToken(resourceUri, clientId, new Uri(redirectUri), PromptBehavior.RefreshSession).AccessToken;
    
    

    But every time when i insert this code the AcquireToken gets red underlined and provides the next error:

    Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext does Not contain as definition for AcquireToken

    I've imported the namespace by downloading the dll and added it to the project. Any ideas why my code keeps erroring? 

    Wednesday, June 15, 2016 11:44 AM

Answers

  • Hi Ruudje87,

    >>"Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext does Not contain as definition for AcquireToken"

    As the document of AuthenticationContext.AcquireToken Method said, it is only applies to: Version: 2.19.208020213, Platform: .NET Desktop. So we need to install Active Directory Authentication Library 2.19.208020213 instead of the latest version.

    You need to uninstall your Active Directory Authentication Library and install the specific version library using following command line code.

    PM>  Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory -Version 2.19.208020213 
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, June 16, 2016 1:17 AM
    Moderator