typescript - 如何在 Ionic 2 应用程序中终止 Google OAuth session (通过 Firebase)?

标签 typescript ionic-framework angular google-oauth ionic2

我的 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/

相关文章:

javascript - 当通过函数添加显式未定义检查时,为什么该对象可能在 typescript 中未定义?

javascript - TypeScript 工厂模式表示属性不存在

ios - 当应用程序通过应用程序商店更新时,在cordova应用程序中保留本地存储

angularjs - 使用带有 Ionic 1 的 FCM 推送通知的多行文本消息

javascript - 如何设置 Angular 组件的动态 "id"HTML 属性?

javascript - 如何使用 Angular 2 扩展外部 JavaScript 库?

angular - ngBootstraps typeahade 导致错误 : Cannot find a differ supporting object '[object Promise]' of type 'object'

javascript - 我可以在不需要 [formGroup] 的情况下使用 [formControl] 吗?

typescript :记录<>,其中值取决于键

angular - 如何重新初始化/重新触发使用动画系统制作的动画?