使用angularfire2返回400的Firebase身份验证

时间:2017-04-21 11:34:22

标签: angular firebase-authentication angularfire2

我已在控制台中通过Google启用身份验证: enter image description here

登录代码:

import { Component, OnInit } from '@angular/core';
import { AngularFire, AuthProviders } from 'angularfire2';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
  user = {};
  constructor(public af: AngularFire) {
    this.af.auth.subscribe(user => {
      if(user) {
        // user logged in
        this.user = user;
      }
      else {
        // user not logged in
        this.user = {};
      }
    });
  }

  login() {
    this.af.auth.login({
      provider: AuthProviders.Google
    });
  }

  ngOnInit() {
  }

}

this.af.auth.login()的调用会产生以下错误。

www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=AIzaSyDyJQVTQI-a-eW2iM70RXAcVHKDb0NP1Ek:1 POST 

https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=AIzaSyDyJQVTQI-a-eW2iM70RXAcVHKDb0NP1Ek 400 ()
core.es5.js:1084ERROR Error: Uncaught (in promise): Error: The given sign-in provider is disabled for this Firebase project. Enable it in the Firebase console, under the sign-in method tab of the Auth section.
    at resolvePromise (zone.js:712) [angular]
    at resolvePromise (zone.js:683) [angular]
    at polyfills.bundle.js:3492:17 [angular]
    at Object.onInvokeTask (core.es5.js:4116) [angular]
    at ZoneDelegate.invokeTask (zone.js:397) [angular]
    at Zone.runTask (zone.js:165) [<root> => angular]
    at drainMicroTaskQueue (zone.js:593) [<root>]
    at XMLHttpRequest.ZoneTask.invoke (zone.js:464) [<root>]

Google搜索显示,当Firebase SDK显示时,这是一个问题。 3.我使用的是最新版本的angularfire2,所以这应该不是问题。

1 个答案:

答案 0 :(得分:1)

如果覆盖angularFire2中的登录配置,则应设置方法和提供程序。尝试登录如下:

import { AuthMethods, AuthProviders } from 'angularfire2';

  login() {
    this.af.auth.login({
      method: AuthMethods.Redirect,
      provider: AuthProviders.Google
    });
  }