2016-03-24 22 views
3

我的Ionic 2 app as Google Authentication通过Firebase,我在应用程序中有一个注销按钮,调用Firebase unauth()方法,但只能验证Firebase引用并且不会终止Google OAuth会话。如何在Ionic 2应用程序中杀死Google OAuth会话(通过Firebase)?

在按下注销按钮并再次按下登录按钮后,用户会自动登录(使用先前的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> 
+0

我有同样的问题。如果您发现任何解决方案,请更新此帖子! – henrikmerlander

回答

0

唯一的工作解决我发现是做一个JSONP asynchronous request to https://accounts.google.com/logout

这是一个“脏”的把戏,并将错误吐出到控制台,但找不到任何其他工作解决方案。让我知道是否有人知道更好的方法。

+0

我搜索了相同的链接,因为我可以看到你有。预计OAuth会话仍然存在。点击注销应用程序时,您并不想从其他Google服务注销用户。 – henrikmerlander

+0

在我的情况下,我确实要注销,以便我可以用不同的Google帐户重新登录。 – nunoarruda

+0

我可以理解它的行为方式,我不希望我的Facebook会话结束,因为我在其他应用程序中注销。很高兴你找到了一种方式来做到这一点! – henrikmerlander