【发布时间】:2018-06-27 10:11:16
【问题描述】:
我收到以下代码:
{"data":{"error":"Invalid grant_type parameter or parameter missing","request":"\/oauth2\/token","method":"Post"}
public class Authentication_Token {
private String Client_ID = "9d99755c****d";
private String Client_Secret= "dbdb21c0de1b***ab1d4cf6a4b92535ed2";
private String Auth_URL= "https://api.imgur.com/oauth2/authorize";
private String Access_Token_URL="https://api.imgur.com/oauth2/token";
@Test
public void oauth2() {
// Still have the same error :
Response resp = given()
.contentType("application/x-www-form-urlencoded")
.parameters("Client ID", Client_ID,
"Client Secret", Client_Secret,
"username", "testbot@gmail.com",
"password", "testbota#1",
"grant_type", "authorization_Code",
"Access_Token_URL", Access_Token_URL)
.auth()
.preemptive().basic(Client_ID, Client_Secret)
.post(Auth_URL);
}
}
【问题讨论】:
-
你为什么在帖子中使用“Auth_URL”?您应该使用令牌 URL,即 Access_Token_URL。我错过了什么吗? oAuth 中有 2 个不同的 URL,首先是 GET,然后是 POST (/token)
-
@umeshinator:您要加载访问令牌还是授权码?第一个网址是
/oauth2/token,第二个网址是/oauth2/authorize。
标签: java rest oauth-2.0 spring-security-oauth2