I have a javascript client and a laravel backend and I am using Oauth.IO for social authentication. I followed the steps specified here: http://docs.oauth.io/#authorizing-the-user-with-both-front-end-and-back-end-sdks
I successfully got state token by calling generateStateToken()
method, but when I send that to $this->oauth->auth()
method I get Invalid Format error. Can you please tell me what this error means and what I am doing wrong.
Client Side
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');
Server Side
// code to get the state token in a different method
$token = $this->oauth->generateStateToken();
return response()->json(['status' => 'success', 'token' => $token]);
-- snip --
// 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();
I have verified that $code
does have the exact state token that I have received on the 1st step.
The value of $credentials
is as follows:
{"status":"error","data":{"code":"Invalid format"},"refreshed":false}
Please help me out here. This error occurs for both for facebook and twitter as well. Let me know if you need more details.