ADAL.NET v3 does not support AcquireToken with UserCredential?
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
Comments
-
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 over 7 yearsI 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 over 7 yearsyou 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 about 7 yearsHey 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 almost 6 yearsWhat is the value for "resource" parameter in the request body? I am guessing but it does not work.
-
wh-dev almost 6 yearsHi @SameekshaKumari, this should answer your question: stackoverflow.com/questions/36297546/…