V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
j1132888093
V2EX  ›  问与答

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

  •  
  •   j1132888093 · 235 天前 · 491 次点击
    这是一个创建于 235 天前的主题,其中的信息可能已经有所发展或是发生改变。

    获取 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确定是对的,大佬们帮忙看看

    2 条回复    2023-09-05 14:05:45 +08:00
    weofuh
        1
    weofuh  
       235 天前
    x-www-form-urlencoded 模式,URL 上的 code 参数去掉试试?
    j1132888093
        2
    j1132888093  
    OP
       235 天前
    @weofuh 我焯!通了,感谢大佬!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2924 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 14:29 · PVG 22:29 · LAX 07:29 · JFK 10:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.