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

Ven*_*a V 5 azure-active-directory

当我尝试使用以下代码创建身份验证标头时.我收到错误消息"AADSTS70002:验证凭据时出错.AADSTS50012:提供了无效的客户端密码." 现在,我确信,我在代码中使用的秘密与我的AAD app注册中使用的秘密不匹配.任何人都可以通过我的应用程序注册或如何在我的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;
    }
}
Run Code Online (Sandbox Code Playgroud)

Nan*_* Yu 5

要为Web应用程序的凭据添加密钥,请单击Azure门户中Settings Azure AD应用程序刀片的"密钥"部分:

  • 添加密钥的描述并选择1或2或年持续时间(或永不过期).
  • 保存配置更改后,最右侧的列将包含键值.请务必回到本节并在点击"保存"后将其复制,这样您就可以在运行时进行身份验证时在客户端应用程序中使用它.

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