jj.
jj.

Reputation: 2390

Switching YouTube user with OAuth2 shows previous user's data in Chrome

I have a Chrome Packaged App that uses oauth2 to authenticate to YouTube. I'm using YouTube to determine the user's channel (via the channel endpoint).

It works for the first user authenticated. But if I switch to a different user, the same YouTube call returns the previous user's data (i.e. channel).

Here are the steps I'm going through.

  1. I get my auth token via a call to getAuthToken:
    chrome.identity.getAuthToken({ interactive: true, scopes: ['https://www.googleapis.com/auth/youtube'] })

  2. I get their channel information. I make a call to the channels endpoint like so: const url = 'https://www.googleapis.com/youtube/v3/channels?part=snippet&mine=true'; const headers = { Authorization: `Bearer ${token}` }; const config = { url, method: 'get', headers, responseType: 'json', }; return axios(config);

  3. This works! The result of the call gives me the channel information.

  4. The user removes their account. I use the same sequence of calls that the Google Demo uses (like this example):

    a. call chrome.identiy.removeCachedAuthToken({ token }) with the token
    b. call https://accounts.google.com/o/oauth2/revoke?token=${token} to revoke it

  5. Everything is cleared out, I think.
    If I look at chrome://identity-internals/ I still see the token, but the Token Status is set to Not Found

The issue:

  1. I repeat from step 1, but I chose a different user.
  2. I confirm that I get a new token that is different than the one I had previously
  3. The call to the YouTube channels api returns the previous user's channel.

Upvotes: 0

Views: 65

Answers (1)

jj.
jj.

Reputation: 2390

It turns out it was a caching issue with youtube.
I had to add 'Cache-Control': 'no-cache' to my headers.

Here is the full headers line:

const headers = {
  Authorization: `Bearer ${token}`,
  'Cache-Control': 'no-cache',
};

Upvotes: 0

Related Questions