I'm trying to implement HybridAuth with ajax.
Code:
PHP: (will be called by ajax)
<?php
header('Content-type: application/json');
$provider = $_GET["provider"];
$config = '../libaries/hybridauth/config.php';
require_once( "../libaries/hybridauth/Hybrid/Auth.php" );
try {
$hybridAuth = new Hybrid_Auth($config);
$adapter = $hybridAuth->authenticate($provider);
$userProfile = json_encode($adapter->getUserProfile());
echo $_GET['callback'] . '(' . "{$userProfile}" . ')';
} catch (Exception $e) {
echo "Ooophs, we got an error: " . $e;
}
?>
Javascript:
socialRegister: function () {
var self = this;
var val = 'provider=' + self.get("provider");
return $.ajax({
type: "GET",
url: path.urlRoot + 'ext/socialRegisterAndAuthentication.inc.php',
dataType: "jsonp",
data: val
});
}
But I always get following error:
XMLHttpRequest cannot load https://api.twitter.com/oauth/authenticate?oauth_token=123. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
I know, that this means, that the Twitter Server is not allowing my origin. Is there a workaround? Is a "One-Page" signUp with ajax possible? (Hopefully yes - on quora.com it works ;) )
TWITTERSETTINGS:
Best Fabian