Firebase Auth SDK 无法刷新令牌以保持登录状态?

Firebase Auth SDK cannot refresh token to maintain logged in status?

我能够使用 Firebase Auth SDK 实现登录用户。但是,当发布的 JWT 过期时,用户似乎已注销,并且 SDK 的自动令牌刷新失败。

我得到的错误是这样的:

{
  "error": {
    "code": 403,
    "message": "Requests to this API securetoken.googleapis.com method google.identity.securetoken.v1.SecureToken.GrantToken are blocked.",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "API_KEY_SERVICE_BLOCKED",
        "domain": "googleapis.com",
        "metadata": {
          "service": "securetoken.googleapis.com",
          "consumer": "projects/621503541053"
        }
      }
    ]
  }
}

我不明白我可能需要授予哪些权限。配置和 API 密钥来自 Firebase 控制台,是为我在那里注册的 Web 应用程序生成的。

文档显示此错误是由于未启用正确的 API 而导致的。根据这个postFirebase authentication,需要启用如下:

Requests to this API firebaseinstallations.googleapis.com method google.firebase.installations.v1.FirebaseInstallationsService.CreateInstallation are blocked.

If you enable restrictions for your API, go to Google Cloud Console -> Credentials, Edit API key -> API restrictions, and enable Firebase Installations API.

com.google.firebase.FirebaseException: An internal error has occurred. [Requests to this API identitytoolkit method google.cloud.identitytoolkit.v1.AuthenticationService.SignInWithIdp are blocked.]

Enable Identity Toolkit API to your API restrictions.

Requests to this API securetoken.googleapis.com method google.identity.securetoken.v1.SecureToken.GrantToken are blocked.

Enable Token Service API to your API restrictions.

启用 “Token Service API”, along with the “Identity Toolkit API” or “Anonymous Sign-in” 应该可以解决错误。