Identity.launchWebAuthFlow() 何时以静默方式完成?

发布于 2025-01-12 01:37:08 字数 660 浏览 4 评论 0原文

我正在尝试使用 identity.launchWebAuthFlow() 从 Firefox 扩展运行 OAuth2 流程。我发现有时,此功能会导致打开一个弹出窗口,我必须登录 Google 等并执行授权,但有时它只是默默地完成,我的应用程序运行完美。

我查看了上面链接的文档,他们说:

请注意,如果不需要身份验证或授权,则此功能将静默完成,无需任何用户交互。

但是浏览器到底如何(这可能取决于浏览器)确定是否“需要”身份验证?它存储什么状态?我很困惑,因为当您调用此函数时,您会返回(嵌入重定向 URL 中)一个访问令牌,该令牌有一个到期时间(在我的情况下为一小时)。但我注意到 launchWebAuthFlow() 会默默地完成即使在访问令牌过期之后,所以即使浏览器在内部存储访问令牌和过期时间,它仍然能够以某种方式做到这一点。

这是专门针对 Google 的 OAuth2 API 的(我没有用其他 API 测试过)。

I'm trying to use identity.launchWebAuthFlow() to run an OAuth2 flow from a Firefox extension. I find that sometimes, this function causes a popup to open where I have to log in to Google etc. and perform the authorization, but sometimes it just completes silently and my app works perfectly.

I looked it up at the docs linked above, and they say:

Note that if neither authentication or authorization are needed, then this function will complete silently, without any user interaction.

But how exactly (and this may be browser-dependent) does the browser determine whether or not authentication is "needed"? What state does it store? I'm confused because when you call this function, you get back (embedded inside a redirect URL) an access token, which has an expiry time (in my case of one hour). But I've noticed that launchWebAuthFlow() completes silently even after the access token is expires, so even if the browser is internally storing the access token and expiry time, it's still able to somehow do it.

This is specifically with Google's OAuth2 API (I haven't tested it with other APIs).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文