简体   繁体   English

Firebase Auth:如何使用id token登录?

[英]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.

相关问题 Firebase Auth ID 令牌验证的必要性,即使有数据库的安全规则? - Necessity of Firebase Auth ID token validation, even if there are security rules of database? 如何使用Cloud Run和Swift验证Firebase ID Token? - How To Verify Firebase ID Token Using Cloud Run and Swift? 谷歌使用 flutter 和 firebase auth 登录 - google sign in with flutter and firebase auth email未验证时如何注销用户,Firebase Auth - How to sign out the user when the email is not verified, Firebase Auth 如何将 Google Play 游戏登录与 Firebase 授权结合起来 - How to combine Google Play Games sign in with Firebase Auth 当前访问令牌已过期时,我如何获取新的访问令牌,谷歌 firebase 身份验证? - How i get new access token when current access token has expired, google firebase auth? Firebase Auth - 没有来自谷歌登录提供商的电子邮件 - Firebase Auth - no email from google sign in provider 使用 Firebase 身份验证和 gAPI? - Using Firebase Auth & gAPI? Firebase Auth - 获取提供商 ID - Firebase Auth - get provider ID 服务器端身份验证令牌验证失败,出现 firebase - server side auth token validation failed with firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM