2016-03-24 23 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