有人做过雅虎的 oauth2 登录吗?

2023-09-05 11:47:51 +08:00
j1132888093  j1132888093

获取 AccessToken 时,官网有两种方式,x-www-form-urlencode 和 json 的形式,我直接调接口都跑不通...

x-www-form-urlencoded (Authorizationredirect_url做了脱敏处理)

curl --location --request POST 'https://api.login.yahoo.com/oauth2/get_token?code=b9r5j5rbw6vug953442kj9qdnretnrrf' \
--header 'Authorization: Basic ZGoweUptazlXVkpxUTBkS1JIZEdPWHB5Sm1ROVdWZHJPVTlYTVVSUk1uUnVWbTF6YldOSGJ6bE5RVDA5Sm5NOVkyOXVjM1Z0' \
--header 'User-Agent: Apifox/1.0.0 ( https://apifox.com)' \
--header 'Accept: */*' \
--header 'Host: api.login.yahoo.com' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'code=b9r5j5rbw6vug953442kj9qdnretnrrf' \
--data-urlencode 'redirect_uri=https://test.com/auth' \
--data-urlencode 'grant_type=authorization_code'

返回

{
    "error": "INVALID_INPUT",
    "error_description": "code parameter cannot be empty for authorization_code grant type"
}

json (client_secretredirect_url做了脱敏处理)

curl --location --request POST 'https://api.login.yahoo.com/oauth2/get_token?code=b9r5j5rbw6vug953442kj9qdnretnrrf' \
--header 'User-Agent: Apifox/1.0.0 ( https://apifox.com)' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: api.login.yahoo.com' \
--header 'Connection: keep-alive' \
--data-raw '{
    "client_id": "dj0yJmk9WVJqQ0dKRHdGOXpyJmQ9WVdrOU9XMURRMnRuVm1zbWNHbzlNQT09JnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PTg0",
    "client_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
    "redirect_uri": "https://test.com/auth",
    "code": "b9r5j5rbw6vug953442kj9qdnretnrrf",
    "grant_type": "authorization_code"
}'

返回

{
    "error": {
        "localizedMessage": "client request is not acceptable or not supported",
        "errorId": "INVALID_INPUT",
        "message": "client request is not acceptable or not supported"
    }
}

client_idclient_secret确定是对的,大佬们帮忙看看

899 次点击
所在节点   问与答  问与答
2 条回复
weofuh
weofuh
2023-09-05 13:31:55 +08:00
x-www-form-urlencoded 模式,URL 上的 code 参数去掉试试?
j1132888093
j1132888093
2023-09-05 14:05:45 +08:00
@weofuh 我焯!通了,感谢大佬!

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/971036

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX