隐式流程
About authenticating with implicit flow.
隐式流是用户认证的一种方式,通过它你的应用可以获得所需的访问令牌和刷新令牌。
🌐 The implicit flow is one of two ways that a user can authenticate and your app can receive the necessary access and refresh tokens.
这个流程是由 Supabase Auth 为你处理的实现细节,但理解隐式流程和 PKCE 流程 之间的区别,对于理解仅客户端认证和服务器端认证的区别很重要。
🌐 The flow is an implementation detail handled for you by Supabase Auth, but understanding the difference between implicit and PKCE flow is important for understanding the difference between client-only and server-side auth.
它是怎么运作的 #
🌐 How it works
登录成功后,用户会被重定向到你的应用,网址看起来像这样:
🌐 After a successful signin, the user is redirected to your app with a URL that looks like this:
1https://yourapp.com/...#access_token=<...>&refresh_token=<...>&...访问令牌和刷新令牌包含在 URL 片段中。
🌐 The access and refresh tokens are contained in the URL fragment.
客户端库:
🌐 The client libraries:
- 检测这种类型的网址
- 提取访问令牌、刷新令牌以及一些额外信息
- 把这些信息保存到本地存储,以便库和你的应用进一步使用
限制 #
🌐 Limitations
隐式流只在客户端有效。网页浏览器默认不会把 URL 片段发送到服务器。这是一个安全特性:
🌐 The implicit flow only works on the client. Web browsers do not send the URL fragment to the server by design. This is a security feature:
- 你可能把你的单页应用托管在第三方服务器上。第三方服务不应该获取你用户的凭证。
- 即使服务器在你的直接控制下,
GET请求及其完整 URL 通常也会被记录。这个方法可以避免在请求或访问日志中泄露凭据。
如果你想在服务器上获取访问令牌和刷新令牌,可以使用PKCE流程。
🌐 If you wish to obtain the access token and refresh token on a server, use the PKCE flow.