对于使用Google OAuth2.0的refresh_token文档中的确切POST,400错误请求错误

wor*_*ith 6 oauth oauth-2.0 google-oauth

我相信我在OAuth文档中运行确切的POST请求(使用我的凭据),但是我收到400错误.我收到了404错误,但随后重置了我的client_secret并开始使用新的client_secret,现在收到错误的请求错误.我有什么想法我做错了吗?

$.ajax({
    url:'https://www.googleapis.com/oauth2/v4/token',
    data:{
    'code':getParameterByName('code'),
        'client_id':'',
        'client_secret':'',
        'redirect_uri':encodeURI(url+'?mail=tokened'),
        'grant_type':'authorization_code'
    },
    dataType:'json',
    method:'POST',
    success:function(response){console.log(response);}});
Run Code Online (Sandbox Code Playgroud)

Han*_* Z. 6

很可能redirect_uri您发送的值已关闭;它应该正是您在授权请求中发送的 URL,即之前重定向到授权端点的 URL。


Joã*_*elo 0

这可能不太可能,但根据使用 OAuth 2.0 for Web Server 应用程序处理 OAuth 2.0 服务器响应部分)中提供的 HTTP/REST 示例,您应该发送内容类型为 的负载,application/x-www-form-urlencoded而不是 JSON。

application/x-www-form-urlencoded除了规范中提到的之外,我还看到其他 OAuth 实现接受 JSON 负载,但也许 Google 实现更严格。