【问题标题】:Angularfire2 The custom token format is incorrectAngularfire2 自定义令牌格式不正确
【发布时间】:2017-02-08 04:14:21
【问题描述】:

我正在生成令牌并传递给 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 令牌有什么区别?

【问题讨论】:

    标签: angular firebase-realtime-database firebase-authentication angularfire angularfire2


    【解决方案1】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2019-12-21
      • 2016-12-04
      • 2017-02-16
      • 2018-01-06
      • 1970-01-01
      • 1970-01-01
      • 2018-10-16
      • 2016-05-04
      • 2018-12-05
      相关资源
      最近更新 更多