Find currently logged user (on google.com)

475 views
Skip to first unread message

Guillaume Boudreau

unread,
May 27, 2010, 10:23:26 AM5/27/10
to Chromium-extensions
Hi,

I'm creating an extension that I'd like to use to update my Google
Latitude extension with.
I was able to achieve that by using OAuth, and the Google Latitude
API.

My problem is that using OAuth, I'm giving the extension 'permanent'
permission to update my current location.
That means that even if I log off from Gmail/Google, then go to work
or something, if my wife uses the Chrome browser on the home computer,
my current location will be updated to 'home'.

That's because the extension has no knowledge of who's currently
logged on Google.com (if anyone). It simply uses the access token
created when I installed the extension, and authorized it to access/
update my Google Latitude data.

So, to fix this:

1. Is there a way to detect the currently logged user on google.com?
If so, I could store the access tokens per user, and user the
appropriate token when one of those is currently logged in.

2. Is there a way to have a callback function that is called when the
user logs on or off from google.com? If so, I could load and save the
access token when that happens, so when a new user who logs in, the
access token of the previous user will not be used.

3. Is there a better way for my extension to access the data of the
currently logged user?

Thank you.

PhistucK

unread,
May 29, 2010, 10:10:19 AM5/29/10
to Guillaume Boudreau, Chromium-extensions
As a somewhat ugly hack, you can also include a content script that works on the log off URL of Google (unless it is a direct redirection, in that case the content script will never be activated), or on all of the Google product pages and addEventListener on the "Log Off" buttons\links in the pages.
Or - you can add a "Log off from Google.com" button in your extension and always use that one to log off.

☆PhistucK



--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Mladen Adamovic

unread,
May 30, 2010, 5:21:37 AM5/30/10
to Guillaume Boudreau, Chromium-extensions
As a hack you get create an appengine application which will return you currently logged user (if any) and invoke it with AJAX. 

Guillaume Boudreau

unread,
May 30, 2010, 6:47:44 AM5/30/10
to Chromium-extensions
I did think about that, but found it was way too complicated /
convoluted to work correctly for everyone.

Thanks for the idea anyway.
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>
> > .

Guillaume Boudreau

unread,
May 30, 2010, 7:00:43 AM5/30/10
to Chromium-extensions
Good idea! I don't think it's really a big hack; more a workaround...
I just need to implement my own web service that will provide that
information to my extension, and use that instead of a Google API to
fetch that information.

Thanks again!

PhistucK

unread,
May 30, 2010, 7:48:06 AM5/30/10
to Guillaume Boudreau, Chromium-extensions
Though if you did not log on to that website through your Google account in the same session, I think, you will never be considered as logged on.

☆PhistucK


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

Guillaume Boudreau

unread,
May 30, 2010, 7:54:58 AM5/30/10
to Chromium-extensions
You're right. For an app-engine app to be able to display the
currently logged user, the user needs to manually log in on the
application...
So back to square one...

On May 30, 7:48 am, PhistucK <phist...@gmail.com> wrote:
> Though if you did not log on to that website through your Google account in
> the same session, I think, you will never be considered as logged on.
>
> ☆PhistucK
>
> On Sun, May 30, 2010 at 14:00, Guillaume Boudreau <
>
>
>
> guillaume.boudr...@gmail.com> wrote:
> > Good idea! I don't think it's really a big hack; more a workaround...
> > I just need to implement my own web service that will provide that
> > information to my extension, and use that instead of a Google API to
> > fetch that information.
>
> > Thanks again!
>
> > On May 30, 5:21 am, Mladen Adamovic <mladen.adamo...@gmail.com> wrote:
> > > As a hack you get create an appengine application which will return you
> > > currently logged user (if any) and invoke it with AJAX.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>
> > .

PhistucK

unread,
May 30, 2010, 7:56:41 AM5/30/10
to Guillaume Boudreau, Chromium-extensions
Hehe personally, I like my Log Off button solution :)
A browser action that logs you off Google.

☆PhistucK


To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

Guillaume Boudreau

unread,
May 30, 2010, 9:42:18 AM5/30/10
to Chromium-extensions
Here's how I did it for now:

- I use a XMLHttpRequest to GET https://www.google.com
- In the HTML I get from that, I look for the currently logged email
address, that appears in the top right corner.

Here's my code:

var currentUser;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(data) {
if (xhr.readyState == 4) {
currentUser = null;
if (xhr.status == 200) {
var re = new RegExp(/<b class="?gb4"?>[\s]*([^<]+@[^<]+)<\/b>/i);
var m = re.exec(xhr.responseText);
if (m && m.length == 2) {
currentUser = m[1];
}
}
console.log("Currently logged user (on google.com): " +
currentUser);
}
};
xhr.open('GET', 'https://www.google.com/', false);
xhr.send();

It seems to work fine for now.

Thanks again for the ideas.

On May 27, 10:23 am, Guillaume Boudreau <guillaume.boudr...@gmail.com>
wrote:
> Hi,
>
> I'm creating an extension that I'd like to use to update my Google
> Latitude extension with.
> I was able to achieve that by using OAuth, and the Google Latitude
> API.
>
> My problem is that using OAuth, I'm giving the extension 'permanent'
> permission to update my current location.
> That means that even if I log off from Gmail/Google, then go to work
> or something, if my wife uses the Chrome browser on the home computer,
> my current location will be updated to 'home'.
>
> That's because the extension has no knowledge of who'scurrentlyloggedon Google.com (if anyone). It simply uses the access token
> created when I installed the extension, and authorized it to access/
> update my Google Latitude data.
>
> So, to fix this:
>
> 1. Is there a way to detect thecurrentlyloggeduser on google.com?

Ben

unread,
May 30, 2010, 3:07:05 PM5/30/10
to chromium-...@chromium.org
I thought about something similar to that, only looking for the GAUSER
cookie with a HEAD request to https://www.google.com. I never got it to
work, but it might be what you're looking for. I just looked at the
cookie again, and it's actually for https://www.google.com/accounts, if
you want to try.
Reply all
Reply to author
Forward
0 new messages