使用自定义令牌的Firebase身份验证错误

I am trying to authenticate user in firebase with KakaoTalk credentials. For that, I've got accesstoken from KakaoTalk. And then trying to authenticate user with that token. Here is my code :

      String token = await kakaoService.getAccessToken();
      await firebaseAuth.signInWithCustomToken(
        token: token,
      );

Got acceess token like this : nmAzFpOF9XrijP-ZoFpQbVluGZ4lLDbZxOCXIAo9c-sAAAFxrID6xA

但是得到这个错误:

自定义令牌格式不正确。请检查文档。 [无效的断言格式。需要3个点分隔的段。 ]

怎么了我想念什么吗?

评论
  • 青鸾
    青鸾 回复

    It seems that the token returns by kakaoService.getAccessToken() is not a valid custom token for Firebase Authentication. In fact, given the error message, it doesn't even seem to be a JWT.

    Custom tokens for Firebase Authentication must have a specific format, that is documented in creating custom tokens. You'll typically want to follow this process to get a valid token for Firebase Authentication:

    1. 将用户登录到身份提供者(在您的情况下为KakaoTalk)。
    2. 从提供者处解码令牌,以获取有关用户的经过验证的信息。
    3. 使用Firebase身份验证管理SDK为用户创建自定义令牌。
    4. 使用该令牌在客户端上登录Firebase。

    第2步和第3步必须在受信任的环境中进行,例如开发计算机,您控制的服务器或Cloud Functions。