我的 Ionic 2 app as Google Authentication通过Firebase我在调用 Firebase unauth()
的应用程序中有一个注销按钮方法,但这只会取消 Firebase 引用的身份验证,不会终止 Google OAuth session 。
在按下注销按钮并再次按下登录按钮后,用户会自动登录(使用之前的 OAuth session ),我不希望这样。
我需要注销按钮来终止 Google OAuth session ,因此当再次按下登录按钮时,它会再次提示输入用户名和密码。我怎样才能做到这一点?
这是我的代码:
首页.ts
import {Page} from 'ionic-angular';
@Page({
templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
firebaseUrl: string;
ref: Firebase;
constructor() {
this.firebaseUrl = 'https://xxx.firebaseio.com';
this.ref = new Firebase(this.firebaseUrl);
}
login() {
this.ref.authWithOAuthPopup("google", (error, authData) => {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
}
});
}
logout() {
this.ref.unauth();
console.log('Logout button clicked');
}
}
主页.html
<ion-navbar *navbar>
<ion-title>
Home
</ion-title>
</ion-navbar>
<ion-content class="home">
<button (click)="login()">Sign in with Google</button>
<button (click)="logout()">Logout</button>
</ion-content>
最佳答案
我找到的唯一可行的解决方案是制作一个 JSONP asynchronous request to https://accounts.google.com/logout
这是一个“肮脏”的把戏,会向控制台吐出错误,但找不到任何其他有效的解决方案。如果有人知道更好的方法,请告诉我。
关于typescript - 如何在 Ionic 2 应用程序中终止 Google OAuth session (通过 Firebase)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36196780/