使用OAuth2切换YouTube用户会在Chrome中显示以前用户的数据

时间:2018-03-05 21:30:49

标签: google-chrome-extension youtube google-chrome-app youtube-data-api google-oauth2

我有一个Chrome打包应用程序,它使用oauth2对YouTube进行身份验证。我正在使用YouTube来确定用户的频道(通过频道终端)。

适用于第一个经过身份验证的用户。但是,如果我切换到其他用户,则同一YouTube通话会返回之前用户的数据(即频道)。

以下是我要经历的步骤。

  1. 我通过调用getAuthToken获得了我的身份验证令牌:
    chrome.identity.getAuthToken({ interactive: true, scopes: ['https://www.googleapis.com/auth/youtube'] })

  2. 我收到了他们的频道信息。我这样调用通道端点: 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. 这个有效!通话结果为我提供了频道信息。

  4. 用户删除了他们的帐户。我使用的是Google Demo使用的相同调用序列(like this example):

    一个。使用令牌发送chrome.identiy.removeCachedAuthToken({ token }) 湾致电https://accounts.google.com/o/oauth2/revoke?token=${token}撤销

  5. 我认为一切都已清除 如果我查看chrome://identity-internals/我仍然看到令牌,但令牌状态设置为Not Found

  6. 问题:

    1. 我从第1步重复,但我选择了不同的用户。
    2. 我确认我得到的新令牌与我以前的令牌不同
    3. 对YouTube频道的调用api会返回上一个用户的频道。

1 个答案:

答案 0 :(得分:0)

事实证明这是youtube的缓存问题 我必须将'Cache-Control': 'no-cache'添加到我的标题中。

这是完整的标题行:

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