Введение в Zend Framework

 Learning Zend Framework


 Zend Framework Reference

  • Zend_Gdata
  • Zend_Http
  • Zend_InfoCard
  • Zend_Json
  • Zend_Layout
  • Zend_Ldap
  • Zend_Loader
  • Zend_Locale
  • Zend_Log
  • Zend_Mail
  • Zend_Markup
  • Zend_Measure
  • Zend_Memory
  • Zend_Mime
  • Zend_Navigation
  • Zend_Oauth
  • Zend_OpenId
  • Zend_Paginator
  • Zend_Pdf
  • Zend_ProgressBar
  • Zend_Queue
  • Zend_Reflection
  • Zend_Registry
  • Zend_Rest

  • Zend_Search_Lucene
  • Zend_Serializer
  • Zend_Server
  • Zend_Service
  • Zend_Session
  • Zend_Soap
  • Zend_Tag
  • Zend_Test
  • Zend_Text
  • Zend_TimeSync
  • Zend_Tool
  • Zend_Tool_Framework
  • Zend_Tool_Project
  • Zend_Translate
  • Zend_Uri
  • Zend_Validate
  • Zend_Version
  • Zend_View
  • Zend_Wildfire
  • Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Ttranslation 27.4% Update 2010-11-28 - Revision 23238 - Version ZF 1.11.x

    36.4. Authenticating with ClientLogin

    The ClientLogin mechanism enables you to write PHP application that acquire authenticated access to Google Services, specifying a user's credentials in the HTTP Client.

    See http://code.google.com/apis/accounts/AuthForInstalledApps.html for more information about Google Data ClientLogin authentication.

    The Google documentation says the ClientLogin mechanism is appropriate for "installed applications" whereas the AuthSub mechanism is for "web applications." The difference is that AuthSub requires interaction from the user, and a browser interface that can react to redirection requests. The ClientLogin solution uses PHP code to supply the account credentials; the user is not required to enter her credentials interactively.

    The account credentials supplied via the ClientLogin mechanism must be valid credentials for Google services, but they are not required to be those of the user who is using the PHP application.

    36.4.1. Creating a ClientLogin authenticated Http Client

    The process of creating an authenticated HTTP client using the ClientLogin mechanism is to call the static function Zend_Gdata_ClientLogin::getHttpClient() and pass the Google account credentials in plain text. The return value of this function is an object of class Zend_Http_Client.

    The optional third parameter is the name of the Google Data service. For instance, this can be 'cl' for Google Calendar. The default is "xapi", which is recognized by Google Data servers as a generic service name.

    The optional fourth parameter is an instance of Zend_Http_Client. This allows you to set options in the client, such as proxy server settings. If you pass NULL for this parameter, a generic Zend_Http_Client object is created.

    The optional fifth parameter is a short string that Google Data servers use to identify the client application for logging purposes. By default this is string "Zend-ZendFramework";

    The optional sixth parameter is a string ID for a CAPTCHA™ challenge that has been issued by the server. It is only necessary when logging in after receiving a CAPTCHA™ challenge from a previous login attempt.

    The optional seventh parameter is a user's response to a CAPTCHA™ challenge that has been issued by the server. It is only necessary when logging in after receiving a CAPTCHA™ challenge from a previous login attempt.

    Below is an example of PHP code for a web application to acquire authentication to use the Google Calendar service and create a Zend_Gdata client object using that authenticated Zend_Http_Client.

    // Enter your Google account credentials
    $email 'johndoe@gmail.com';
    $passwd 'xxxxxxxx';
    try {
    $client Zend_Gdata_ClientLogin::getHttpClient($email$passwd'cl');
    } catch (
    Zend_Gdata_App_CaptchaRequiredException $cre) {
    'URL of CAPTCHA image: ' $cre->getCaptchaUrl() . "\n";
    'Token ID: ' $cre->getCaptchaToken() . "\n";
    } catch (
    Zend_Gdata_App_AuthException $ae) {
    'Problem authenticating: ' $ae->exception() . "\n";

    $cal = new Zend_Gdata_Calendar($client);

    36.4.2. Terminating a ClientLogin authenticated Http Client

    There is no method to revoke ClientLogin authentication as there is in the AuthSub token-based solution. The credentials used in the ClientLogin authentication are the login and password to a Google account, and therefore these can be used repeatedly in the future.

    digg delicious meneame google twitter technorati facebook