google-chrome-extension - 如何使用 chrome.identity.launchWebAuthFlow 缓存身份验证令牌?
问题描述
我正在使用chrome.identity.launchWebAuthFlow
方法从我们的 OAuth2 服务器启动 OAuth2 令牌生成。
在 Identity API 文档中,指定要对用户进行身份验证,有两种可用方法:getAuthToken
和launchWebAuthFlow
. 我们使用后者,因为如文档中所述:
如果您的应用程序使用自己的服务器对用户进行身份验证,您将需要使用 launchWebAuthFlow。
我们正在努力缓存结果。在阅读 的文档时getAuthToken
,似乎涉及到一些智能缓存。
Chrome 捕获响应并将 and 存储access_token
在renew_token
浏览器中(在此处可见:)chrome://identity-internals/
。仅当过期时,Chromeaccess_token
才会向 OAuth 服务器请求。access_token
但是,使用launchWebAuthFlow
时,我们很难使用 Chrome 缓存,并且它每次都会调用我们的 OAuth 服务器。
有谁知道如何使用 API 的这种方法缓存结果?
解决方案
getAuthToken 仅指使用 Google 自己的 api 进行身份验证,如果您想自己做类似的事情,则必须自己实现。
只需使用 chrome.storage 来存储传入的凭据,并在使用它们时,然后仅在经过足够的时间后才触发 launchWebAuthFlow,否则无论如何都进行 fetch 调用,如果它返回未经身份验证,则刷新您的令牌
推荐阅读
- node.js - 一定时间后自动删除 mongo DB 中的文档
- sql - 从单个表中打印未引用的孤儿
- excel - 如何检查excel单元格是否包含单词
- java - 如何将此kotlin代码中的“应用”转换为java?
- node.js - 如何正确使用 nodemon 的 --inspect 选项?
- excel - 更改存储在同一工作表中的多个数据透视表的数据源
- c - 何时在 C 中指定函数类型?
- appcelerator-titanium - 无法打包 Appcelerator android 模块
- angular - 对象数组的角度拖放
- scala - 尝试通过 Slick 访问 MySql 数据库时出现语法错误