JS API - Async Loading & AuthSub Issue

206 views
Skip to first unread message

Bobby

unread,
Oct 11, 2009, 1:07:35 AM10/11/09
to Google Data Protocol
In the GData JS API (up to the current version) there's an issue
involving AuthSub authentication. When the GData library is loaded
with a callback option, AuthSub doesn't complete, for example:
google.load('gdata', '2.0', {callback: function(){}});

The callback causes GData to load asynchronously. When loading
completes, the AuthSub token in the URL (when one is available) isn't
consumed. The end result is that invoking google.accounts.user.login()
starts AuthSub normally and redirects the user to the AuthSubJS
handler, but when it redirects back (with the token in the URL), the
token is never consumed and AuthSub doesn't complete.

You can reproduce this issue using the HTML at the end of this post.
The process is the following:
1. Click to load GData.
2. Click to login, and follow the directions.
3, When redirected back, click to load GData again.

In step 3, when GData loads it should consume the AuthSub token in the
URL to wrap up authentication, but it doesn't

Here's the HTML to reproduce this behavior (logo-small.png is in there
because AuthSub JS requires an image in the same domain as the page):

<html>
<head>
<script type="text/javascript" src="http://www.google.com/jsapi"></
script>
</head>
<body>
<img src="logo-small.png" />
<script type="text/javascript">
function loadGDataAsync() {
google.load('gdata', '2.0', {"callback" : function() { alert
('Loaded'); }});
}
function logMeIn() {
scope = "http://www.google.com/calendar/feeds/";
var token = google.accounts.user.login(scope);
}
</script>
<input type="button" value="Load GData" onclick="loadGDataAsync
();" />
<input type="button" value="Login" onclick="alert(logMeIn());" />
</body>
</html>

Eric Bidelman

unread,
Oct 13, 2009, 5:35:41 PM10/13/09
to google-he...@googlegroups.com
The issue is that your aysnc callback is conflicting with the authsub callback.  You can address this by
calling the google.gdata.onLoad() method before executing your own code.

Eric

Bobby

unread,
Oct 14, 2009, 7:30:48 PM10/14/09
to Google Data Protocol
Ah nice, that really helps me out. Thanks.

Bobby

On Oct 13, 5:35 pm, Eric Bidelman <api.e...@google.com> wrote:
> The issue is that your aysnc callback is conflicting with the authsub
> callback.  You can address this by calling the google.gdata.onLoad() method
> before executing your own code.
>
> Eric
>
Reply all
Reply to author
Forward
0 new messages