【问题标题】:AADSTS70002: Error validating credentials. AADSTS50012: Invalid client secret is providedAADSTS70002:验证凭据时出错。 AADSTS50012:提供的客户端密码无效
【发布时间】:2018-12-13 07:33:55
【问题描述】:

当我尝试使用以下代码创建身份验证标头时。我收到一条错误消息:“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;
    }
}

【问题讨论】:

    标签: azure-active-directory


    【解决方案1】:

    要为您的 Web 应用程序凭据添加密钥,请单击 Azure Portal 中 Azure AD 应用程序的 Settings 刀片中的“密钥”部分:

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

    请点击here 了解更多关于如何向您的 Azure Active Directory 租户注册和更新您的应用程序的详细信息。

    【讨论】:

    • 使用 AD 中的 Keys 部分(不是 Key Vault)
    【解决方案2】:

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

    secret key must be encoded before making request.

    我将 + 替换为 %2B 和我的密钥中的提琴手请求,它就像一个魅力。

    Invalid client secret error on Azure App Service

    【讨论】:

      猜你喜欢
      • 2019-05-19
      • 2019-02-23
      • 2014-08-12
      • 1970-01-01
      • 2017-07-17
      • 2020-09-03
      • 1970-01-01
      • 2017-01-01
      • 2021-01-01
      相关资源
      最近更新 更多