通过Google Apps登录

问题描述:

如何通过我们的Google Apps帐户验证我的用户身份? 我也需要访问他们的电子邮件。通过Google Apps登录

我读过Oauth,但我不知道这是否正确。

我正在使用PHP。

我在我写的一个库中使用这段代码来从gmail提取联系信息。 http://www.oriontechnologysolutions.com/programming/libgoog_php。 此特定功能将验证一个帐户并传回用于访问Google服务的验证令牌。

function login() { 
     $response = Array(); 
     if(isset($this->domain)) 
      $email = $this->username . '@' . $this->domain; 
     else 
      $email = $this->username; 
     $requestString = "service=".$this->service."&Email=".urlencode($email)."&Passwd=".urlencode($this->passwd)."&source=".self::source; 

     $c = curl_init(); 
     curl_setopt($c, CURLOPT_URL, self::loginUrl); 
     curl_setopt($c, CURLOPT_POST, 1); 
     curl_setopt($c, CURLOPT_POSTFIELDS, $requestString); 
     curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 

     $res = curl_exec($c); 
     $httpCode = curl_getinfo($c, CURLINFO_HTTP_CODE); 
     foreach(explode("\n", $res) as $line) { 
      if(strpos($line, "=") != false) { 
       gooDebug("Exploding $line\n", 4); 
       list($name, $value) = explode("=", $line); 
       $response[$name] = $value; 
      } 
     } 
     if($httpCode !=200) 
      return($response); 

     $this->authTok = $response['Auth']; 
     return($this->authTok); 
    }