ADAL.NET v3 does not support AcquireToken with UserCredential?

10,776

Solution 1

Use UserPasswordCredential class instead which is a subclass of UserCredential

Solution 2

Try UserPasswordCredential, the class had to be renamed in v3.

Solution 3

FYI, it seems as though they have removed this functionality from ADAL. source

To authenticate with a users username/password combo, I believe you will have to use HttpClient and make the post request yourself.

Post to:

https://login.microsoftonline.com/yourdomain.onmicrosoft.com/oauth2/token

with:

resource={resource}&client_id={clientid}&grant_type=password&username={username}&password={password}&scope=openid&client_secret={clientsecret}

in the request

Solution 4

This fixes the issue for the UserCredentials, but you also seems to be a change to the AuthenticationContext type which no longer seems to have an AcquireToken method. You can address this by using AcquireTokenAsync

Share:
10,776
cuongle
Author by

cuongle

Email: [email protected]

Updated on June 15, 2022

Comments

  • cuongle
    cuongle almost 2 years

    In ADAL.NET 2.x, we use the below code to acquire token from Azure AD using UserCredential and it works perfectly:

     var authContext = new AuthenticationContext(Authority);
     var userCredential = new UserCredential(username, password);
     var token = authContext.AcquireToken(ResourceUrl, ClientId, userCredential);
    

    When I upgraded ADAL.NET v3 today, the code cannot be compiled anymore because on the new version, UserCredential does not have overloaded constructor with username and password.

    How I can workaround this with the new version of ADAL.NET v3?

  • Russell at ISC
    Russell at ISC over 7 years
    I get AADSTS70002: The request body must contain the following parameter: 'client_secret or client_assertion'. Trace ID: 8be09594-65c2-4e2d-bce2-17980f739371 Correlation ID: 7312b657-f6d4-4d0b-8fc2-c66f1b9f0325 Timestamp: 2016-12-28 16:14:16Z
  • Kanishk Panwar
    Kanishk Panwar over 7 years
    you are trying to use confidential client (web api) id for a native application. You need to create a new native app id for your flow
  • ZoomVirus
    ZoomVirus about 7 years
    Hey im using this and in debug configuration it works fine but in release i get AADSTS50126: Invalid username or password even though im using the same password username, any idea what could cause this?
  • Sameeksha Kumari
    Sameeksha Kumari almost 6 years
    What is the value for "resource" parameter in the request body? I am guessing but it does not work.
  • wh-dev
    wh-dev almost 6 years
    Hi @SameekshaKumari, this should answer your question: stackoverflow.com/questions/36297546/…