我正在尝试通过使用用户凭证来检索访问令牌。
我正在使用AcquireTokenAsync方法来检索令牌,而我正在使用以资源,客户端ID和用户凭据作为参数的构造函数。
pl_id=MDR_PLZ
ln_id=01N
dt_concluded=20191106115958796600
tx_seq_nr=122586
ts_seq_nr=1078
us_id=c0507387
我期望返回访问令牌,但是获取令牌时出现异常。以下是我收到的错误消息。
public async Task<IHttpactionResult> GetToken()
{
AuthenticationResult authenticationResult = null;
try
{
string authority = "https://login.microsoftonline.com/tenant";
string resource ="2424-234-234234-234-23-32423";
string username = "yxyzzz";
string password = "password";
string clientId="2424-234-234234-234-23-32423";
var useridpassword = new UserPasswordCredential(username,password);
AuthenticationContext context = new AuthenticationContext(authority);
context.TokenCache.Clear();
authenticationResult = await context.AcquireTokenAsync(resource,clientId,useridpassword);
return authenticationResult.accessToken;
}
catch (Exception ex)
{
throw ex;
}
}