【问题标题】:Google oAuth2 unauthorized_client by refresh_token谷歌 oAuth2 未授权客户端,由 refresh_token
【发布时间】:2013-09-05 12:03:58
【问题描述】:

我正在尝试在我的控制台 perl 脚本中使用来自 oAuth2 Web 重定向身份验证的刷新令牌。客户端 ID 与我在 javascript 中使用的客户端 ID 相同且正确,我检查了 5 次,与我在 Google API 控制台中使用的相同。

客户端密码检查了两次,都是正确的。

刷新令牌是用approval_prompt=force&access_type=offline创建的

这是我使用的 perl 示例代码:

# -----------------------------------------------------------------------------------
my $CLIENT_ID     = 'XXXXX.apps.googleusercontent.com';
my $CLIENT_SECRET = 'YYYYYYYYYYY';
# -----------------------------------------------------------------------------------
# TESTING
my $refresh_token = '1/is_5_minutes_old';
# -----------------------------------------------------------------------------------

my $string = '';
$string .= 'grant_type=refresh_token';
$string .= '&client_id=' . $CLIENT_ID;
$string .= '&client_secret=' . $CLIENT_SECRET;
$string .= '&refresh_token=' . $refresh_token;

$ua = LWP::UserAgent->new;

my $req =
  HTTP::Request->new( POST => 'https://accounts.google.com/o/oauth2/token' );
$req->content_type('application/x-www-form-urlencoded');
$req->content($string);
print $string . "\n";
my $res = $ua->request($req);
print $res->as_string;

它的反应:

HTTP/1.1 400 Bad Request
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Connection: close
Date: Mon, 02 Sep 2013 10:50:26 GMT
Pragma: no-cache
Server: GSE
Content-Type: application/json
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Alternate-Protocol: 443:quic
Client-Date: Mon, 02 Sep 2013 10:50:26 GMT
Client-Peer: 74.125.136.84:443
Client-Response-Num: 1
Client-SSL-Cert-Issuer: /C=US/O=Google Inc/CN=Google Internet Authority G2
Client-SSL-Cert-Subject: /C=US/ST=California/L=Mountain View/O=Google Inc/CN=accounts.google.com
Client-SSL-Cipher: RC4-SHA
Client-SSL-Warning: Peer certificate not verified
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block

{
  "error" : "unauthorized_client"
}

我希望你有一个想法可以提供帮助。

感谢

【问题讨论】:

    标签: perl google-plus google-oauth


    【解决方案1】:

    无效的客户端通常意味着客户端 ID 和客户端密码不匹配,或者其中一个存在拼写错误(尽管您提到您已经仔细检查过这一点!)。您的代码中没有任何错误。

    当您检索刷新令牌时,您能否尝试将随附的访问令牌放入 tokeinfo 端点,并确保那里的客户端 ID 值与您配置的值相匹配:https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=

    可能值得转储请求以确保其中没有错误(例如,内容长度标头太短或类似的)。

    【讨论】:

    【解决方案2】:

    转储请求是关键。为了帮助,这是我之前烤过的一个..

    ==POST== 
    https://accounts.google.com/o/oauth2/token
    refresh_token=1/_PEzU2m71wertwertwerJUtrtrytrytryf3trytryoCo
    &client_id=612222222225
    &client_secret=Q7334534543534yKLu
    &grant_type=refresh_token
    

    您是否使用了客户 ID 的缩写形式,即。只是数字?

    【讨论】:

      猜你喜欢
      • 2018-01-22
      • 1970-01-01
      • 2015-02-01
      • 2020-03-27
      • 1970-01-01
      • 1970-01-01
      • 2011-10-26
      • 2014-11-21
      • 2015-08-01
      相关资源
      最近更新 更多