Angularfire2 自定义令牌格式不正确

Angularfire2 The custom token format is incorrect

我正在生成令牌并传递给 Angularfire2,它一直给我:

The custom token format is incorrect

而相同的标记在 Angular1 Firebase 上运行良好。

    constructor(af: AngularFire) {
    let token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhZG1pbiI6ZmFsc2UsImRlYnVnIjpmYWxzZSwiZXhwIjoxNDkwODAwOTYzLCJkIjp7InVpZCI6Im1heGllLGZlZW5leSJ9LCJ2IjowLCJpYXQiOjE0NzUxNjI1NjN9.YAyRVxL6dlw4WCVHY8lCd09qJ2tY9rg_dTQZtkW5zAs';

    af.auth.login(token, {})
        .then((success) => {
          console.log("Firebase success: " + JSON.stringify(success));
        })
        .catch((error) => {
          console.log("Firebase failure: " + JSON.stringify(error));
        });
  }

有谁知道 Angular2 令牌与 Angular1 Firebase 令牌有什么区别?

假设您的令牌是 valid jwt token,这可能是因为它之前有效,您可以使用自定义令牌进行身份验证,并将额外的参数传递到登录中。

af.auth.login(token, {
  provider: AuthProviders.Custom,
  method: AuthMethods.CustomToken
})
.then(...)
.catch(...);

有关其他可用登录参数的更多详细信息,您可以查看 source code

如果这不起作用,您可能需要更深入地了解您是如何形成 jwt 令牌的。我也可以帮你。