【发布时间】: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