locked
AuthenticationContext.AcquireTokenByAuthorizationCode RRS feed

  • Question

  • Hello,

    I am having trouble with the AcquireTokenByAuthorizationCode.

    If using the method AcquireTokenByAuthorizationCode, I get this error:

    'Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext' does not contain a definition for 'AcquireTokenByAuthorizationCode' and no extension method 'AcquireTokenByAuthorizationCode' accepting a first argument of type 'Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext' could be found (are you missing a using directive or an assembly reference?)

    If I will use the available method AcquireTokenByAuthorizationCodeAsync, I get this error:

    Cannot implicitly convert type 'System.Threading.Tasks.Task<Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult>' to 'Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult'

    Below are the codes I am using:

                 

     var queryString = Request.QueryString;

    string authCode = queryString["code"];

     TokenCache tokenCache = new TokenCache();
     AuthenticationContext authContext = new AuthenticationContext(string.Format(AuthorityUri, _configuration.ADTenant), tokenCache);
     ClientCredential clientCredentials = new ClientCredential(_configuration.ClientId, _configuration.ClientSecret);
    AuthenticationResult authResult = authContext.AcquireTokenByAuthorizationCode(authCode, new Uri(_configuration.RedirectUri), clientCredentials);


    Tuesday, September 20, 2016 9:03 AM