如何在 angularfire2/auth 退出后断开 Google 身份验证?
How to disconnect from Google authentication after angularfire2/auth signOut?
我正在使用 Angular 和 Firebase 构建网站。我正在使用 Angularfire2 和 AngularFireAuth 库以及 GoogleAuthProvider (Google) 作为我的身份验证提供程序。
这是我的服务代码:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
@Injectable()
export class AuthenticationService {
user: Observable<firebase.User>;
constructor(public afAuth: AngularFireAuth) {
this.user = afAuth.authState;
}
login() {
this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
}
logout() {
this.afAuth.auth.signOut();
}
}
当用户'logs out'访问我的站点时,它可以工作,但似乎'cache' Google 身份验证。因此,当他们第二次尝试登录时,我 运行 遇到了一些问题:
- 不允许用户选择另一个 Google 帐户登录。
- 用户自动登录...这似乎是一个安全问题。另一个用户可以使用同一台共享 PC,并以以前的用户身份登录,而无需输入密码。
我做错了什么?有什么方法可以阻止 angularfire2/auth 缓存这些凭证?当用户退出我的网站时,有没有办法让用户退出 Google?
这是预料之中的,因为它们是 2 个独立的系统,并且每个 Auth 状态都是单独存储的。 Firebase Auth signOut
让您退出 Firebase。要从 Google 注销,您必须转到 google 并注销。如果这对您的应用至关重要,您可以随时在 Firebase Auth 上注销,重定向到 google 注销页面:
auth.signOut().then(() => {
window.location.assign('https://accounts.google.com/Logout');
}, (error) => {
console.log(error);
});
作为建议,您可以更谨慎地按照 link 中的 "solution" 进行操作。
我在我的应用程序中使用它以防用户无权访问数据库,但您可以在任何地方添加 iframe。
注销服务:
function LogoutService($location){
this.logOut = function(myAuth){
myAuth.$signOut().then(() => {
$location.path("/logout");
}, (error) => {
console.log(error);
});
};
};
路由器:
.when('/logout', {
templateUrl : "login/logout.html"
})
logout.html:
<div class="container" >
<p >{{logUser.unauthUser}} unauthorized. Try again.</p>
<iframe id="logoutframe" src="https://accounts.google.com/logout" style="display: none"></iframe>
</div>
我正在使用 Angular 和 Firebase 构建网站。我正在使用 Angularfire2 和 AngularFireAuth 库以及 GoogleAuthProvider (Google) 作为我的身份验证提供程序。
这是我的服务代码:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
@Injectable()
export class AuthenticationService {
user: Observable<firebase.User>;
constructor(public afAuth: AngularFireAuth) {
this.user = afAuth.authState;
}
login() {
this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider());
}
logout() {
this.afAuth.auth.signOut();
}
}
当用户'logs out'访问我的站点时,它可以工作,但似乎'cache' Google 身份验证。因此,当他们第二次尝试登录时,我 运行 遇到了一些问题:
- 不允许用户选择另一个 Google 帐户登录。
- 用户自动登录...这似乎是一个安全问题。另一个用户可以使用同一台共享 PC,并以以前的用户身份登录,而无需输入密码。
我做错了什么?有什么方法可以阻止 angularfire2/auth 缓存这些凭证?当用户退出我的网站时,有没有办法让用户退出 Google?
这是预料之中的,因为它们是 2 个独立的系统,并且每个 Auth 状态都是单独存储的。 Firebase Auth signOut
让您退出 Firebase。要从 Google 注销,您必须转到 google 并注销。如果这对您的应用至关重要,您可以随时在 Firebase Auth 上注销,重定向到 google 注销页面:
auth.signOut().then(() => {
window.location.assign('https://accounts.google.com/Logout');
}, (error) => {
console.log(error);
});
作为建议,您可以更谨慎地按照 link 中的 "solution" 进行操作。 我在我的应用程序中使用它以防用户无权访问数据库,但您可以在任何地方添加 iframe。
注销服务:
function LogoutService($location){
this.logOut = function(myAuth){
myAuth.$signOut().then(() => {
$location.path("/logout");
}, (error) => {
console.log(error);
});
};
};
路由器:
.when('/logout', {
templateUrl : "login/logout.html"
})
logout.html:
<div class="container" >
<p >{{logUser.unauthUser}} unauthorized. Try again.</p>
<iframe id="logoutframe" src="https://accounts.google.com/logout" style="display: none"></iframe>
</div>