From 06f945f27840b53e57795dadbc38e76f7e11ab1c Mon Sep 17 00:00:00 2001 From: Horus3 Date: Mon, 24 Feb 2014 16:42:14 +0100 Subject: init --- .../manual/core/en/zend.gdata.authsub.html | 253 +++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 zend/documentation/manual/core/en/zend.gdata.authsub.html (limited to 'zend/documentation/manual/core/en/zend.gdata.authsub.html') diff --git a/zend/documentation/manual/core/en/zend.gdata.authsub.html b/zend/documentation/manual/core/en/zend.gdata.authsub.html new file mode 100644 index 0000000..078e3da --- /dev/null +++ b/zend/documentation/manual/core/en/zend.gdata.authsub.html @@ -0,0 +1,253 @@ + + + + + Authenticating with AuthSub - Zend Framework Manual + + + + + + + + +
+ + + + + + + + +
+ Using Google Analytics + + + + +
+
+

Authenticating with AuthSub

+ + +

+ The AuthSub mechanism enables you to write web applications + that acquire authenticated access Google Data services, + without having to write code that handles user credentials. +

+ +

+ See » http://code.google.com/apis/accounts/AuthForWebApps.html + for more information about Google Data AuthSub 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 AuthSub mechanism are + entered by the user of the web application. Therefore they must be + account credentials that are known to that user. +

+ +

Note: Registered applications
+ + + + Zend_Gdata currently does not support use of secure tokens, + because the AuthSub authentication does not support passing a digital certificate + to acquire a secure token. +
+

+ +

Creating an AuthSub authenticated Http Client

+ + +

+ Your PHP application should provide a hyperlink to the + Google URL that performs authentication. The static function + Zend_Gdata_AuthSub::getAuthSubTokenUri() + provides the correct URL. The arguments to this function include + the URL to your PHP application so that Google can + redirect the user's browser back to your application after the user's + credentials have been verified. +

+ +

+ After Google's authentication server redirects the user's browser + back to the current application, a GET request parameter is set, + called token. The value of this parameter is a single-use token + that can be used for authenticated access. This token can be converted into a multi-use + token and stored in your session. +

+ +

+ Then use the token value in a call to + Zend_Gdata_AuthSub::getHttpClient(). + This function returns an instance of Zend_Http_Client, + with appropriate headers set so that subsequent requests your + application submits using that HTTP Client are also authenticated. +

+ +

+ 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 + HTTP Client. +

+ +
  1. $my_calendar = 'http://www.google.com/calendar/feeds/default/private/full';
  2. +
  3.  
  4. +
  5. if (!isset($_SESSION['cal_token'])) {
  6. +
  7.     if (isset($_GET['token'])) {
  8. +
  9.         // You can convert the single-use token to a session token.
  10. +
  11.         $session_token =
  12. +
  13.             Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
  14. +
  15.         // Store the session token in our session.
  16. +
  17.         $_SESSION['cal_token'] = $session_token;
  18. +
  19.     } else {
  20. +
  21.         // Display link to generate single-use token
  22. +
  23.         $googleUri = Zend_Gdata_AuthSub::getAuthSubTokenUri(
  24. +
  25.             'http://'. $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'],
  26. +
  27.             $my_calendar, 0, 1);
  28. +
  29.         echo "Click <a href='$googleUri'>here</a> " .
  30. +
  31.              "to authorize this application.";
  32. +
  33.         exit();
  34. +
  35.     }
  36. +
  37. }
  38. +
  39.  
  40. +
  41. // Create an authenticated HTTP Client to talk to Google.
  42. +
  43. $client = Zend_Gdata_AuthSub::getHttpClient($_SESSION['cal_token']);
  44. +
  45.  
  46. +
  47. // Create a Gdata object using the authenticated Http Client
  48. +
  49. $cal = new Zend_Gdata_Calendar($client);
+ +
+ +

Revoking AuthSub authentication

+ + +

+ To terminate the authenticated status of a given token, use the + Zend_Gdata_AuthSub::AuthSubRevokeToken() + static function. Otherwise, the token is still valid for + some time. +

+ +
  1. // Carefully construct this value to avoid application security problems.
  2. +
  3. $php_self = htmlentities(substr($_SERVER['PHP_SELF'],
  4. +
  5.                          0,
  6. +
  7.                          strcspn($_SERVER['PHP_SELF'], "\n\r")),
  8. +
  9.                          ENT_QUOTES);
  10. +
  11.  
  12. +
  13. if (isset($_GET['logout'])) {
  14. +
  15.     Zend_Gdata_AuthSub::AuthSubRevokeToken($_SESSION['cal_token']);
  16. +
  17.     unset($_SESSION['cal_token']);
  18. +
  19.     header('Location: ' . $php_self);
  20. +
  21.     exit();
  22. +
  23. }
+ + +

Note: Security notes
+ + + + The treatment of the $php_self variable in the + example above is a general security guideline, it is not + specific to Zend_Gdata. You should always filter content you + output to HTTP headers. +
+ + + Regarding revoking authentication tokens, it is recommended to + do this when the user is finished with her Google Data session. + The possibility that someone can intercept the token and use + it for malicious purposes is very small, but nevertheless it is + a good practice to terminate authenticated access to any service. +
+

+
+
+
+ + + + + + + + + +
+ Using Google Analytics + + + + +
+
+ +
+ + \ No newline at end of file -- cgit v1.2.3