" Invalid_Client"尝试进行身份验证时出错 [英] "Invalid_Client" error when trying to authenticate

查看:192
本文介绍了" Invalid_Client"尝试进行身份验证时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试获取访问令牌时,我最终会遇到"无效客户端"。错误响应。



我已经对我的客户ID和密码进行了两次和三次检查,我也尝试创建一个新的应用程序并进行测试。同样的错误。我已经尝试将strict_ssl设置为false,看看是否有所不同,但是没有,同样的错误。我还尝试使用谷歌Chrome REST客户端构建
的POST请求,我也尝试使用现有的用于连接到MS Translator的库。在所有情况下,同样的错误。所以我非常确信在这一点上我的代码可能不是问题 - 也许是我用设置的应用程序
的东西?无论我是难过。

When attempting to get an access token, I wind up with an "invalid client" error response.

I've double and triple checked my Client ID and Secret, and I've tried creating a new application and testing with that as well. Same error. I've tried setting strict_ssl to false to see if that made a difference, but no, same error. I've also tried construction the POST request with the Google Chrome REST Client, and I've tried using existing libraries designed to connect to MS Translator as well. In all cases, same error. So I'm pretty convinced at this point it's likely not my code that's the problem -- maybe something to do with the application I've set up? Regardless I'm stumped.

如果它是代码,但是: 

In case it IS the code, though: 

我的应用程序是用node.js编写的,我使用广泛使用的'请求'库来处理http请求。这是相关代码,MY_CLIENT_ID和MY_CLIENT_SECRET替换实际值:

My app is written in node.js, and I'm using the widely-used 'request' library to handle http requests. Here's the relevant code, with MY_CLIENT_ID and MY_CLIENT_SECRET replacing the real values:

function getAccessToken(clientId, clientSecret, callback) {
  console.log("CID: " + encodeURIComponent(clientId) + " / CS: " + encodeURIComponent(clientSecret));
  request.post({
    url: "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13",
    form: {
      "grant_type": "client_credentials",
      "client_id": encodeURIComponent(clientId),
      "client_secret": encodeURIComponent(clientSecret),
      "scope": "http://api.microsofttranslator.com"
    }
  }, function(err, resp, body) {
    if(err) return callback(err);
    try {
      var accessToken = JSON.parse(body).access_token;
      if(accessToken) {
        callback(null, accessToken);
      } else {
        callback(body);
      }
    } catch(e) {
      callback(e);
    }
  });
}

getAccessToken("MY_CLIENT_ID", "MY_CLIENT_SECRET", function(err, accessToken) {
  if (err) {
    console.log("error: " + err);
  } else {
    console.log("Got access token: " + accessToken);
  }
});

运行脚本时出现以下错误:

I get the following error upon running the script:

{"error":"invalid_client","error_description":"ACS50012: Authentication failed.\r\nTrace ID: 11b92b2f-9441-473b-a1b0-3a2f3be6c48a\r\nCorrelation ID: eb3b32fa-ea6a-4ab7-aca6-bcbcd70be71b\r\nTimestamp: 2015-11-20 19:26:49Z"}

任何想法可能出错?

推荐答案

使用IOS Swift进行身份验证时遇到了类似的问题。我的问题最终是clientID和clientSecret的编码。我需要自定义编码的字符集。代码如下:

I had a similar problem when authenticating using IOS Swift. My problem ended up being the encoding of the clientID and clientSecret. I needed to customize the character set for encoding. Code below:

  customAllowedSet =   NSCharacterSet (charactersInString: " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnioqrstuvwxyz0123456789 _!*'();:@

let customAllowedSet = NSCharacterSet(charactersInString:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnioqrstuvwxyz0123456789_!*'();:@


,#[] + = /"
,#[]+=/")

不确定这是否是问题,并且不确定如何自定义Java的编码。

Not sure if this is the problem, and not sure how to customize the encoding for Java.

您在MSDN中的错误代码表示:

Your error code in MSDN says:

身份验证失败。 (邮件中可能有更多详细信息。)

Authentication failed. (There may be more details in the message.)

当多租户应用程序尝试获取要访问的令牌时最近同意该应用程序的Azure AD租户的Graph API,令牌请求可能会暂时失败并显示错误ACS50012。要解决此问题,请等待几分钟
然后重试。或者,让同意后提供同意的租户管理员登录该应用程序。

When a multi-tenant application tries to acquire a token to access the Graph API for an Azure AD tenant that has recently consented to the application, the token request might fail temporarily with error ACS50012. To resolve the problem, wait a few minutes and try again. Or, have the tenant administrator who provided consent log on to the application after consenting.


这篇关于" Invalid_Client"尝试进行身份验证时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆