Zend_Gdata_ClientLogin.xml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.gdata.clientlogin">
  4. <title>Authenticating with ClientLogin</title>
  5. <para>
  6. The ClientLogin mechanism enables you to write <acronym>PHP</acronym> application
  7. that acquire authenticated access to Google Services,
  8. specifying a user's credentials in the <acronym>HTTP</acronym> Client.
  9. </para>
  10. <para>
  11. See <ulink
  12. url="http://code.google.com/apis/accounts/AuthForInstalledApps.html">http://code.google.com/apis/accounts/AuthForInstalledApps.html</ulink>
  13. for more information about Google Data ClientLogin authentication.
  14. </para>
  15. <para>
  16. The Google documentation says the ClientLogin mechanism is appropriate
  17. for "installed applications" whereas the AuthSub mechanism is
  18. for "web applications." The difference is that AuthSub requires
  19. interaction from the user, and a browser interface that can react
  20. to redirection requests. The ClientLogin solution uses <acronym>PHP</acronym> code to
  21. supply the account credentials; the user is not required to enter her
  22. credentials interactively.
  23. </para>
  24. <para>
  25. The account credentials supplied via the ClientLogin mechanism must
  26. be valid credentials for Google services, but they are not required
  27. to be those of the user who is using the <acronym>PHP</acronym> application.
  28. </para>
  29. <sect2 id="zend.gdata.clientlogin.login">
  30. <title>Creating a ClientLogin authenticated Http Client</title>
  31. <para>
  32. The process of creating an authenticated <acronym>HTTP</acronym> client using
  33. the ClientLogin mechanism is to call the static function
  34. <methodname>Zend_Gdata_ClientLogin::getHttpClient()</methodname>
  35. and pass the Google account credentials in plain text.
  36. The return value of this function is an object of class
  37. <classname>Zend_Http_Client</classname>.
  38. </para>
  39. <para>
  40. The optional third parameter is the name of the Google Data
  41. service. For instance, this can be 'cl' for Google Calendar.
  42. The default is "xapi", which is recognized by Google Data
  43. servers as a generic service name.
  44. </para>
  45. <para>
  46. The optional fourth parameter is an instance of <classname>Zend_Http_Client</classname>.
  47. This allows you to set options in the client, such as proxy
  48. server settings. If you pass <constant>NULL</constant> for this
  49. parameter, a generic <classname>Zend_Http_Client</classname> object is created.
  50. </para>
  51. <para>
  52. The optional fifth parameter is a short string that Google Data
  53. servers use to identify the client application for logging
  54. purposes. By default this is string "Zend-ZendFramework";
  55. </para>
  56. <para>
  57. The optional sixth parameter is a string ID for a
  58. <trademark>CAPTCHA</trademark> challenge that has been issued by
  59. the server. It is only necessary when logging in after receiving
  60. a <trademark>CAPTCHA</trademark> challenge from a previous
  61. login attempt.
  62. </para>
  63. <para>
  64. The optional seventh parameter is a user's response to a
  65. <trademark>CAPTCHA</trademark> challenge that has been issued by
  66. the server. It is only necessary when logging in after receiving
  67. a <trademark>CAPTCHA</trademark> challenge from a previous
  68. login attempt.
  69. </para>
  70. <para>
  71. Below is an example of <acronym>PHP</acronym> code for a web application
  72. to acquire authentication to use the Google Calendar service
  73. and create a <classname>Zend_Gdata</classname> client object using that authenticated
  74. <classname>Zend_Http_Client</classname>.
  75. </para>
  76. <programlisting language="php"><![CDATA[
  77. // Enter your Google account credentials
  78. $email = 'johndoe@gmail.com';
  79. $passwd = 'xxxxxxxx';
  80. try {
  81. $client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, 'cl');
  82. } catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
  83. echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "\n";
  84. echo 'Token ID: ' . $cre->getCaptchaToken() . "\n";
  85. } catch (Zend_Gdata_App_AuthException $ae) {
  86. echo 'Problem authenticating: ' . $ae->exception() . "\n";
  87. }
  88. $cal = new Zend_Gdata_Calendar($client);
  89. ]]></programlisting>
  90. </sect2>
  91. <sect2 id="zend.gdata.clientlogin.terminating">
  92. <title>Terminating a ClientLogin authenticated Http Client</title>
  93. <para>
  94. There is no method to revoke ClientLogin authentication as there
  95. is in the AuthSub token-based solution. The credentials used
  96. in the ClientLogin authentication are the login and password
  97. to a Google account, and therefore these can be used repeatedly
  98. in the future.
  99. </para>
  100. </sect2>
  101. </sect1>