我想實現聯合登錄到我的GAE應用程序PHP。GAE上的Basel類捲曲替換
我看過幾個第三方,如janrain或OAuth plugin,但我不能很容易地整合它們,我不想支付或有限制。我只想要一件簡單的東西,它將掛鉤到GAE認證模型中。
目前,我有谷歌和雅虎,因爲他們是使用不要求用戶名端點的只有2個,而我可以用UserService::createLoginUrl()
我要添加Facebook,Twitter和微軟,加上其他人我猜,但這些都是我現在的目標。
我開始與Facebook我想使用Facebook連接器。最初,我開始使用Javascript API,它運行良好,直到你坐在防火牆後面並且Facebook被阻止(然後$.getScript()
失敗無法處理),所以我開始查看用戶可見的PHP庫(至少阻塞是) ,b)不是我對陷印和處理的責任,以及c)很適合我擁有的URL端點模型)
問題是BaseFacebook類使用cURL。 GAE沒有。
有沒有人知道一種方法來建立身份驗證到GAE,所以我可以使用login: required
或者如果沒有,任何人誰擁有更好的流/ curl知識比我更換baselah類cURL的東西。下面是這是造成我的悲傷功能:
/**
* Makes an HTTP request. This method can be overridden by subclasses if
* developers want to do fancier things or use something other than curl to
* make the request.
*
* @param string $url The URL to make the request to
* @param array $params The parameters to use for the POST body
* @param CurlHandler $ch Initialized curl handle
*
* @return string The response text
*/
protected function makeRequest($url, $params, $ch=null) {
if (!$ch) {
$ch = curl_init();
}
$opts = self::$CURL_OPTS;
if ($this->getFileUploadSupport()) {
$opts[CURLOPT_POSTFIELDS] = $params;
} else {
$opts[CURLOPT_POSTFIELDS] = http_build_query($params, null, '&');
}
$opts[CURLOPT_URL] = $url;
// disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
// for 2 seconds if the server does not support this header.
if (isset($opts[CURLOPT_HTTPHEADER])) {
$existing_headers = $opts[CURLOPT_HTTPHEADER];
$existing_headers[] = 'Expect:';
$opts[CURLOPT_HTTPHEADER] = $existing_headers;
} else {
$opts[CURLOPT_HTTPHEADER] = array('Expect:');
}
curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
$errno = curl_errno($ch);
// CURLE_SSL_CACERT || CURLE_SSL_CACERT_BADFILE
if ($errno == 60 || $errno == 77) {
self::errorLog('Invalid or no certificate authority found, '.
'using bundled information');
curl_setopt($ch, CURLOPT_CAINFO,
dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fb_ca_chain_bundle.crt');
$result = curl_exec($ch);
}
// With dual stacked DNS responses, it's possible for a server to
// have IPv6 enabled but not have IPv6 connectivity. If this is
// the case, curl will try IPv4 first and if that fails, then it will
// fall back to IPv6 and the error EHOSTUNREACH is returned by the
// operating system.
if ($result === false && empty($opts[CURLOPT_IPRESOLVE])) {
$matches = array();
$regex = '/Failed to connect to ([^:].*): Network is unreachable/';
if (preg_match($regex, curl_error($ch), $matches)) {
if (strlen(@inet_pton($matches[1])) === 16) {
self::errorLog('Invalid IPv6 configuration on server, '.
'Please disable or get native IPv6 on your server.');
self::$CURL_OPTS[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4;
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$result = curl_exec($ch);
}
}
}
if ($result === false) {
$e = new FacebookApiException(array(
'error_code' => curl_errno($ch),
'error' => array(
'message' => curl_error($ch),
'type' => 'CurlException',
),
));
curl_close($ch);
throw $e;
}
curl_close($ch);
return $result;
}
我沒想到的GAE認證是可擴展的,謝謝澄清。感謝GITKit鏈接,這將是非常有用的。 –