[英]Firebase Auth: How to sign in using id token?
Is there a way to share anonymous user sessions with Firebase Auth?有没有办法与 Firebase Auth 共享匿名用户会话?
What I would like to is to get the current id token:我想要的是获取当前的 id 令牌:
final idToken = FirebaseAuth.instance.currentUser!.getIdToken();
Then, use this idToken
to authenticate the same anonymous user in a different app.然后,使用此
idToken
对不同应用程序中的同一匿名用户进行身份验证。
FirebaseAuth.instance.signInWithToken(idToken);
With signInWithCustomToken()
method, you can use a custom auth token to sign in a user on different website.使用
signInWithCustomToken()
方法,您可以使用自定义身份验证令牌在不同网站上登录用户。 As documented here如此处所述
Firebase gives you complete control over authentication by allowing you to authenticate users or devices using secure JSON Web Tokens (JWTs).
Firebase 允许您使用安全令牌 (JWT) 对用户或设备进行身份验证,从而让您完全控制身份验证 JSON Web 令牌 (JWT)。 You generate these tokens on your server, pass them back to a client device, and then use them to authenticate via the
signInWithCustomToken()
method.您在服务器上生成这些令牌,将它们传回客户端设备,然后使用它们通过
signInWithCustomToken()
方法进行身份验证。You can create a custom token with the Firebase Admin SDK, or you can use a third-party JWT library if your server is written in a language which Firebase does not natively support.
您可以使用 Firebase Admin SDK 创建自定义令牌,或者如果您的服务器使用 Firebase 本身不支持的语言编写,则可以使用第三方 JWT 库。
The Firebase Admin SDK has a built-in method for creating custom tokens.
Firebase Admin SDK 有一个用于创建自定义令牌的内置方法。 At a minimum, you need to provide a uid, which can be any string but should uniquely identify the user or device you are authenticating.
至少,您需要提供一个 uid,它可以是任何字符串,但应该唯一标识您正在验证的用户或设备。 These tokens expire after one hour.
这些令牌在一小时后过期。
After you create a custom token, you should send it to your client app.
创建自定义令牌后,您应该将其发送到您的客户端应用程序。 The client app authenticates with the custom token by calling
signInWithCustomToken()
客户端应用程序通过调用
signInWithCustomToken()
使用自定义令牌进行身份验证
Also check out these links for more information and examples:另请查看这些链接以获取更多信息和示例:
Authenticate with Firebase Using a Custom Authentication System使用自定义身份验证系统通过 Firebase 进行身份验证
Firebase auth - login user from app in website Firebase auth - 从网站中的应用程序登录用户
How to use the same firebase anonymous user in a flutter app 如何在 flutter 应用程序中使用相同的 firebase 匿名用户
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.