Google chrome extension Chrome扩展-来自“的令牌”;启动WebAuthFlow“;一小时后过期,需要用户交互才能获得新的
我在服务人员中使用Google chrome extension Chrome扩展-来自“的令牌”;启动WebAuthFlow“;一小时后过期,需要用户交互才能获得新的,google-chrome-extension,oauth,token,Google Chrome Extension,Oauth,Token,我在服务人员中使用launchWebAuthFlow对选择在其Google驱动器中备份扩展设置的用户进行身份验证。 当用户单击登录按钮时,它会向服务人员(MV3,显然是“后台脚本”)发送一条消息,服务人员执行以下操作: const redirectUrl = await browser.identity.launchWebAuthFlow({ 'url': _createAuthEndpoint(), 'interactive': true })
launchWebAuthFlow
对选择在其Google驱动器中备份扩展设置的用户进行身份验证。
当用户单击登录按钮时,它会向服务人员(MV3,显然是“后台脚本”)发送一条消息,服务人员执行以下操作:
const redirectUrl = await browser.identity.launchWebAuthFlow({
'url': _createAuthEndpoint(),
'interactive': true
})
const url = new URL(redirectUrl);
const urlParams = new URLSearchParams(url.hash.slice(1));
const params = Object.fromEntries(urlParams.entries());
await browser.storage.local.set({googleToken: params.access_token});
用于构造身份验证url的帮助器方法:
function _createAuthEndpoint() {
const redirectURL = browser.identity.getRedirectURL();
const { oauth2 } = browser.runtime.getManifest();
const clientId = oauth2.client_id;
const authParams = new URLSearchParams({
client_id: clientId,
response_type: 'token',
redirect_uri: redirectURL,
scope: 'openid ' + oauth2.scopes.join(' '),
});
return `https://accounts.google.com/o/oauth2/auth?${authParams.toString()}`;
}
它可以正常工作大约一个小时,之后令牌失效,我需要得到一个新的令牌。如果尝试将launchWebAuthFlow
与interactive:false
一起使用,则会出现错误“需要用户交互”
有没有一种方法可以在没有用户交互的情况下刷新令牌