如何使用 chrome.identity.launchWebAuthFlow 缓存授权令牌?
How to cache auth token with chrome.identity.launchWebAuthFlow?
我正在使用 chrome.identity.launchWebAuthFlow
方法从我们的 OAuth2 服务器启动 OAuth2 令牌生成。
在Identity API文档中,指定了对用户进行身份验证,有两种可用的方法:getAuthToken
和launchWebAuthFlow
。我们使用后者,因为如文档中所述:
If your app uses its own server to authenticate users, you will need to use launchWebAuthFlow.
我们正在努力缓存结果。在阅读 getAuthToken
的文档时,似乎涉及到一些智能缓存。
Chrome 捕获响应并将 access_token
和 renew_token
存储在浏览器中(此处可见:chrome://identity-internals/
)。 Chrome 向 OAuth 服务器 请求 access_token
只有 当 access_token
过期时。
但是,使用 launchWebAuthFlow
,我们很难使用 Chrome 缓存,它每次都会调用我们的 OAuth 服务器。
有谁知道如何使用 API 的这种方法来缓存结果?
getAuthToken 仅指使用 Google 自己的 api 进行身份验证,如果你想自己做类似的事情,你必须自己实现它。
只需使用 chrome.storage 来存储传入的凭据和使用它们的时间,然后仅在经过足够的时间后才触发 launchWebAuthFlow,否则无论如何都要进行提取调用,如果返回时未经身份验证则刷新您的令牌
我正在使用 chrome.identity.launchWebAuthFlow
方法从我们的 OAuth2 服务器启动 OAuth2 令牌生成。
在Identity API文档中,指定了对用户进行身份验证,有两种可用的方法:getAuthToken
和launchWebAuthFlow
。我们使用后者,因为如文档中所述:
If your app uses its own server to authenticate users, you will need to use launchWebAuthFlow.
我们正在努力缓存结果。在阅读 getAuthToken
的文档时,似乎涉及到一些智能缓存。
Chrome 捕获响应并将 access_token
和 renew_token
存储在浏览器中(此处可见:chrome://identity-internals/
)。 Chrome 向 OAuth 服务器 请求 access_token
只有 当 access_token
过期时。
但是,使用 launchWebAuthFlow
,我们很难使用 Chrome 缓存,它每次都会调用我们的 OAuth 服务器。
有谁知道如何使用 API 的这种方法来缓存结果?
getAuthToken 仅指使用 Google 自己的 api 进行身份验证,如果你想自己做类似的事情,你必须自己实现它。
只需使用 chrome.storage 来存储传入的凭据和使用它们的时间,然后仅在经过足够的时间后才触发 launchWebAuthFlow,否则无论如何都要进行提取调用,如果返回时未经身份验证则刷新您的令牌