Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential does not take 2 parameters?

旧城冷巷雨未停 提交于 2019-12-29 06:24:09

问题


I'm using ADAL in my code. One thing I want to use is to use different credentials, so I can authorize different users against Azure AD in the console program.

Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential cred = new Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential("username", "password");

This is the line I use to create the user credential. I use nuget get the latest ADAL. However, this line shows error:

The best overloaded method match for 'Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential.UserCredential(string, Microsoft.IdentityModel.Clients.ActiveDirectory.UserAuthType)' has some invalid arguments

However, according to https://msdn.microsoft.com/en-us/library/microsoft.identitymodel.clients.activedirectory.usercredential.aspx

UserCredential(String, String)
Constructor to create credential with client id and secret 

Anyone knows what I did wrong?

Thanks


回答1:


In ADAL .NET v3 UserCredential Constructor is no longer supports the second parameter (password), instead you need to use UserPasswordCredential class

Example

var credentials = new UserPasswordCredential(userName, password);
var context = new AuthenticationContext(authorityUri);
var authResult = context.AcquireTokenAsync(resource, clientId, credentials).Result;


来源:https://stackoverflow.com/questions/37443977/microsoft-identitymodel-clients-activedirectory-usercredential-does-not-take-2-p

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!