【问题标题】:Bad request on posting to google Oauth2 token url发布到谷歌 Oauth2 令牌网址的错误请求
【发布时间】:2015-05-02 01:13:23
【问题描述】:

这是我在此网址上发帖时收到的数据:

POST https://accounts.google.com/o/oauth2/token 400(错误请求)

Object {error: "invalid_request", error_description: "参数不 允许此消息类型:session_state"}

我不知道问题可能是什么。此代码在离子应用程序中被调用。

$scope.gpluslogin = function() {
        var ref = window.open('https://accounts.google.com/o/oauth2/auth?client_id=' + clientId + '&redirect_uri=http://localhost/callback&scope=https://www.googleapis.com/auth/plus.login%20https://www.googleapis.com/auth/plus.me&approval_prompt=auto&response_type=code&access_type=offline&include_granted_scopes=false', '_blank', 'location=no');
        //var ref = window.open('https://accounts.google.com/o/oauth2/auth?client_id=' + clientId + '&redirect_uri=http://localhost/callback&scope=https://www.googleapis.com/auth/plus.login%20https://www.googleapis.com/auth/plus.me&approval_prompt=force&response_type=code', '_blank', 'location=no');
        ref.addEventListener('loadstart', function(event) { 
            if((event.url).startsWith("http://localhost/callback")) {
                requestToken = (event.url).split("code=")[1];
                $http({method: "post", url: "https://accounts.google.com/o/oauth2/token", data: "client_id=" + clientId + "&client_secret=" + clientSecret + "&redirect_uri=http://localhost/callback" + "&grant_type=authorization_code" + "&code=" + requestToken })
                    .success(function(data) {
                        accessToken = data.access_token;
                        console.log(data);
                        console.log(accessToken);
                        $.ajax({
                          url: "http://192.168.137.118:3000/api/v1/save_gp_auth",
                          data: {'gp_auth_token':accessToken,'user_id':$rootScope.currentuser_id},
                          dataType: "json",
                          type: "post",
                          success: function(data){
                            if(data.gp_status=="gp_saved" || data.gp_status=="gp_updated")
                              { $rootScope.gp_toggle=true;
                                 if($rootScope.fb_toggle==true && $rootScope.gp_toggle==true)
                                    $scope.toggle_status="both_connected";
                                  else
                                    $scope.toggle_status="gp_connected";
                              }
                          }
                        });
                    })
                    .error(function(data, status) {
                        console.log(data);
                    });
                ref.close();
            }
        });
    }

但是,当我将范围更改为“电子邮件”之类的内容时,它会起作用并为我提供访问令牌。

【问题讨论】:

  • 我看到您正在使用我的 ng-cordova-oauth 插件中的大量代码。您决定提取它而不是仅仅使用插件的任何原因?
  • @NicRaboy 我在这里找到了您博客文章中的代码:blog.nraboy.com/2014/07/using-oauth-2-0-service-ionicframework,我没有使用该插件,因为我只需要对 googleplus 进行身份验证

标签: oauth-2.0 ionic-framework google-oauth


【解决方案1】:

鉴于它适用于 email 范围,我猜这是您的其他范围的 URI 编码问题。

尝试使用encodeURIComponent 的URI 编码范围,即:

encodeURIComponent("https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me")

哪个输出:https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.login%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.me

【讨论】:

  • 根据所提供的信息,我同意这一点。然而,我的一部分说我们错过了一些故事。可能是 Google Dashboard 中的配置问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-14
  • 1970-01-01
  • 2016-12-03
  • 2016-06-22
  • 2015-03-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多