如何在Ionic 2应用中杀死Google OAuth会话(通过Firebase)?

时间:2016-03-24 09:24:48

标签: typescript ionic-framework angular google-oauth ionic2

我的Ionic 2 app as Google Authentication通过Firebase,我在应用中有一个退出按钮,调用Firebase unauth()方法,但只取消认证Firebase参考,并且不会终止Google OAuth会话。

按下注销按钮并再次按下登录按钮后,用户将自动登录(使用之前的OAuth会话),我不希望这样。

我需要退出按钮才能终止Google OAuth会话,因此再次按下登录按钮时,会再次提示输入用户名和密码。我怎样才能做到这一点?

这是我的代码:

home.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');
    }

}

home.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>

1 个答案:

答案 0 :(得分:0)

我找到的唯一可行解决方案是制作JSONP asynchronous request to https://accounts.google.com/logout

这是一个&#34;脏&#34;欺骗和吐出错误到控制台但无法找到任何其他工作解决方案。如果有人知道更好的方法,请告诉我。