AADSTS70002:验证凭据时出错.AADSTS50012:提供的客户端密码无效



当我尝试使用以下代码创建身份验证标头时。我收到一条错误消息,指出"AADSTS70002:验证凭据时出错。AADSTS50012:提供的客户端密码无效。现在,我确定我在代码中使用的机密与我的 AAD 应用注册中使用的机密不匹配。任何人都可以帮助我如何从我的应用程序注册中获取客户端密码或如何在我的 O365 帐户目录中添加新的应用程序标识符。

private string GetAuthenticationHeader(AuthenticationInformation authenticationInformation){
try{
return RetryHelper.InvokeWithRetries(() =>
{
var clientCredential = new ClientCredential(authenticationInformation.ClientId, authenticationInformation.AppSecret);
var ac = new AuthenticationContext(authenticationInformation.Authority);
AuthenticationResult ar = ac.AcquireToken(authenticationInformation.Resource, clientCredential);
return ar.CreateAuthorizationHeader();
});
}
catch (Exception ex){
return ex.Message;
}
}

若要为 Web 应用程序的凭据添加密钥,请在 Azure 门户中单击 Azure AD 应用的"Settings"边栏选项卡中的"密钥"部分:

  • 为密钥添加描述,并选择 1 或 2 或年持续时间(或永不过期(。
  • 保存配置更改后,最右侧的列将包含键值。请务必返回此部分并在点击保存后复制它,以便在运行时进行身份验证期间在客户端应用程序中使用它。

请单击此处了解有关如何使用 Azure Active Directory 租户注册和更新应用程序的更多详细信息。

我在尝试通过提琴手获取图形令牌时收到此错误。 这是因为我的secret key had few unnecessary characters like + and /.

secret key must be encoded before making request.

我用%2B替换了 +,我的密钥中的小提琴手请求就像一个魅力。

Azure 应用服务上的客户端密码错误无效

最新更新