【发布时间】:2013-08-09 05:40:26
【问题描述】:
我正在尝试将从客户端应用程序获得的 OAuth 一次性使用代码交换为服务器上的访问令牌和刷新令牌。我得到的回应是:
{
"error" : "redirect_uri_mismatch"
}
我的 POST 请求是:
POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded
code={My Code}&
client_id={My Client ID}&
client_secret={My Client Secret}&
grant_type=authorization_code
我已根据 API 控制台中的内容检查了我的客户端 ID 和客户端密码,并且它们匹配。
我通过以下 Java 代码在我的客户端上获得一次性使用代码:
static final List<String> SCOPES = Arrays.asList(new String[]{"https://www.googleapis.com/auth/plus.login","https://www.googleapis.com/auth/userinfo.email"});
String scope = String.format("oauth2:server:client_id:%s:api_scope:%s", SERVER_CLIENT_ID, TextUtils.join(" ", SCOPES));
final String token = GoogleAuthUtil.getToken(c, email, scope);
我的 API 控制台中有一个 redirect_uri,但由于我尝试使用跨客户端授权(如 here 所述),因此我故意将其按要求排除在 POST 请求之外:
当它为令牌交换代码时,它不应在 POST 中包含“redirect_uri”参数。
知道我做错了什么吗?
【问题讨论】: