1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| function googleAuthenticate($username,$password,$service)
{
$ch = curl_init();
if(!$ch)
return false;
curl_setopt($ch,CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
$post_fields = "Email=" .urlencode($username)."&Passwd=".urlencode($password)
//."&source=".urlencode($source)
."accountType=".urlencode('GOOGLE')."&service=".urlencode($service);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$reponse = curl_exec($ch);
echo $reponse;
curl_close($ch);
if (strpos($reponse,'200 OK')==FALSE)
{
return false;
}
//recuperation du code d'authentification
preg_match("/(Auth=)([\w|-]+)/",$reponse,$matches);
if(!$matches[2])
return false;
return $matches[2];
} |
Partager