vishala1 / gdata-samples

Automatically exported from code.google.com/p/gdata-samples
0 stars 0 forks source link

Hybrid authentication demo always fails (as does my code) #7

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Use the demo and grant permission. http://googlecodesamples.com/hybrid/

This always fails for me with the following output:

Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with 
message 'Expected response code 200, got 401 <HTML> <HEAD> <TITLE>Unknown 
authorization header</TITLE> </HEAD> <BODY BGCOLOR="#FFFFFF" 
TEXT="#000000"> <H1>Unknown authorization header</H1> <H2>Error 401</H2> 
</BODY> </HTML> ' in /srv/www/www.googlecodesamples.com/ZendGdata-
1.7.7/library/Zend/Gdata/App.php:689 Stack trace: 
#0 /srv/www/www.googlecodesamples.com/ZendGdata-
1.7.7/library/Zend/Gdata.php(218): Zend_Gdata_App->performHttpRequest
('GET', 'http://spreadsh...', Array, NULL, NULL, NULL) 
#1 /srv/www/www.googlecodesamples.com/ZendGdata-
1.7.7/library/Zend/Gdata/App.php(842): Zend_Gdata->performHttpRequest
('GET', 'http://spreadsh...', Array) 
#2 /srv/www/www.googlecodesamples.com/ZendGdata-
1.7.7/library/Zend/Gdata/App.php(742): Zend_Gdata_App->get
('http://spreadsh...', NULL) 
#3 /srv/www/www.googlecodesamples.com/ZendGdata-
1.7.7/library/Zend/Gdata/App.php(204): Zend_Gdata_App->importUrl
('http://spreadsh...', 'Zend_Gdata_Spre...', NULL) #4 /srv/www/www.googl 
in /srv/www/www.googlecodesamples.com/ZendGdata-
1.7.7/library/Zend/Gdata/App.php on line 689

Please provide any additional information below.

I see the same behavior with my application. I haven't been able to track 
down the problem.

Original issue reported on code.google.com by roma...@gmail.com on 8 Apr 2010 at 7:22

GoogleCodeExporter commented 8 years ago
I found the problem and here's a simple solution.  According to Federated Login 
docs, there's a NOTE: "If you request an OAuth token and none is returned, if 
may be because you've previously acquired an access token keyed to the specific 
user and scope. For privacy considerations, Google expects third-party 
applications to store OAuth tokens, which are long-lived, rather than request a 
new token every time the application needs to access the user's Google 
service.".

The issue is that when the page is reloaded after the OpenID+OAuth process has 
completed (so the request token is set as a URL parameter 
'openid_ext2_request_token'), then the page re-attempts to get the access 
token.  Since the access token isn't returned, the remaining code breaks around 
the regex parsing to construct a new OAuthToken in getAccessToken().  The 
simplest workaround is to store the access token as a session variable.  The 
access token is an instance of OAuthToken and is not serializable as php 
session variable, so you need to store the access key's "key" and "secret" 
properties instead.  Here's how:

Change the following (around line 105 in index.php):

$access_token = getAccessToken($request_token);

Instead:

  if(isset($_SESSION["access_token_key"])) {
    $access_token = new OAuthToken(urldecode($_SESSION["access_token_key"]),
                                 urldecode($_SESSION["access_token_secret"]));

  } else {
    $access_token = getAccessToken($request_token);
    $_SESSION["access_token_key"] = $access_token->key;
    $_SESSION["access_token_secret"] = $access_token->secret;
  }

Original comment by burkes...@gmail.com on 14 Jul 2010 at 2:10

GoogleCodeExporter commented 8 years ago
Here is error I got, any idea ? it came out after I granted
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 
'Expected response code 200, got 500 Internal Error' in 
/home/michael/tmp/ZendFramework-1.11.0/library/Zend/Gdata/App.php:709 Stack 
trace: #0 /home/michael/tmp/ZendFramework-1.11.0/library/Zend/Gdata.php(219): 
Zend_Gdata_App->performHttpRequest('GET', 'http://spreadsh...', Array, NULL, 
NULL, NULL) #1 
/home/michael/tmp/ZendFramework-1.11.0/library/Zend/Gdata/App.php(875): 
Zend_Gdata->performHttpRequest('GET', 'http://spreadsh...', Array) #2 
/home/michael/tmp/ZendFramework-1.11.0/library/Zend/Gdata/App.php(763): 
Zend_Gdata_App->get('http://spreadsh...', NULL) #3 
/home/michael/tmp/ZendFramework-1.11.0/library/Zend/Gdata/App.php(205): 
Zend_Gdata_App->importUrl('http://spreadsh...', 'Zend_Gdata_Spre...', NULL) #4 
/home/michael/tmp/ZendFramework-1.11.0/library/Zend/Gdata.php(162): 
Zend_Gdata_App->getFeed('http://spreadsh...', 'Zend_Gdata_Spre...') #5 
/home/michael/tmp/ZendFramework-1.11.0/library/Zend/Gdata/Spreadsheets.php(150):
 Zend_Gdata->getFeed('ht in 
/home/michael/tmp/ZendFramework-1.11.0/library/Zend/Gdata/App.php on line 709

Original comment by m...@ask-cs.com on 30 Dec 2010 at 2:16