我有一个 javascript 客户端和一个 laravel 后端,我正在使用 Oauth.IO 进行社交身份验证。我按照此处指定的步骤操作:http: //docs.oauth.io/#authorizing-the-user-with-both-front-end-and-back-end-sdks
我通过调用generateStateToken()
方法成功获得了状态令牌,但是当我将它发送到$this->oauth->auth()
方法时,我得到了Invalid Format错误。你能告诉我这个错误是什么意思,我做错了什么。
客户端
var selectedAuth = 'facebook';
$.post('http://localhost/auth/v1/social', {provider: selectedAuth, get_state_token: 1}, function(data){
OAuth.popup(selectedAuth)
.done(function(result) {
console.log(result);
$.post('http://localhost/auth/v1/social', {provider: selectedAuth, code: data.token, access_token: result.access_token}, function(data){
console.log(data);
}, 'json');
})
.fail(function (err) {
//handle error with err
});
}, 'json');
服务器端
// code to get the state token in a different method
$token = $this->oauth->generateStateToken();
return response()->json(['status' => 'success', 'token' => $token]);
-- 剪辑 --
// code to get access token from state token in another method
$provider = 'facebook';
$request_object = $this->oauth->auth($provider, array(
'code' => $code
));
$credentials = $request_object->getCredentials();
我已经验证$code
确实有我在第一步收到的确切状态令牌。的值$credentials
如下:
{"status":"error","data":{"code":"Invalid format"},"refreshed":false}
请帮帮我。facebook 和 twitter 也会出现此错误。如果您需要更多详细信息,请告诉我。