To do auth, first you need to go firebase.console.com to enable the auth methods, for example, enable google, github...

Enable goolge is quite simple, just one click, enable Github, Twitter, you need to do more configuration.

Follow the link: https://firebase.google.com/docs/auth/web/github-auth

After successfully enable it, we create a service to do the auth:

import {AuthProviders, FirebaseAuthState, FirebaseAuth} from "angularfire2";
import {Injectable} from "@angular/core"; @Injectable()
export class AuthService { private authState: FirebaseAuthState = null; constructor(public auth$: FirebaseAuth) {
auth$.subscribe((state: FirebaseAuthState) => {
this.authState = state;
});
} get authenticated(): boolean {
return this.authState !== null;
} get id(): string {
return this.authenticated ? this.authState.uid : '';
} signIn(provider: number): firebase.Promise<FirebaseAuthState> {
return this.auth$.login({provider})
.catch(error => console.log('ERROR @ AuthService#signIn() :', error));
} signInWithGithub(): firebase.Promise<FirebaseAuthState> {
return this.signIn(AuthProviders.Github)
} signInWithGoogle(): firebase.Promise<FirebaseAuthState> {
return this.signIn(AuthProviders.Google);
} signInWithTwitter(): firebase.Promise<FirebaseAuthState> {
return this.signIn(AuthProviders.Twitter);
} signOut(): void {
this.auth$.logout();
}
}

Using it in controller:

<section class="signup">
<button md-button (click)="signInWithGoogle()">Google</button>
<button md-button (click)="signInWithTwitter()">Twitter</button>
<button md-button (click)="signInWithGithub()">Github</button>
</section>
import {Component, OnInit} from '@angular/core';
import {AuthService} from "../shared";
import {Router} from "@angular/router"; @Component({
selector: 'app-signup',
templateUrl: './signup.component.html',
styleUrls: ['./signup.component.css']
})
export class SignupComponent implements OnInit { constructor(private auth: AuthService, private router: Router) { } ngOnInit() {
} signInWithGithub(){
this.auth.signInWithGithub()
.then(this.postSignIn.bind(this))
} signInWithTwitter(){
this.auth.signInWithTwitter()
.then(this.postSignIn.bind(this))
} signInWithGoogle(){
this.auth.signInWithGoogle()
.then(this.postSignIn.bind(this))
} postSignIn() {
console.log("Auth id: ", this.auth.id);
this.router.navigate(['/home']);
} }

Happy Auth!

[Angular2Fire] Firebase auth (Google, Github)的更多相关文章

  1. [AngularFire2] Auth with Firebase auth -- email

    First, you need to enable the email auth in Firebase console. Then implement the auth service: login ...

  2. istio的安全(概念)

    Istio 安全(概念) 目录 Istio 安全(概念) 高层架构 Istio身份 身份和证书管理 认证 Mutial TLS认证 宽容(Permissive)模式 安全命名 认证架构 认证策略 策略 ...

  3. GitHub:Google

    ylbtech-GitHub:Google 1.返回顶部 · horenso 探しやすいコードで漢字直接入力    Perl  Apache-2.0 94710Updated on 19 Apr · ...

  4. [Firebase + PWA] Keynote: Progressive Web Apps on Firebase

    Link : Video. 1. Firebase Auth: provides simple login with Github, Google, Facebook, Twittr. Link 2. ...

  5. 用 Flutter 和 Firebase 轻松构建 Web 应用

    作者 / Very Good Ventures Team 我们 (Very Good Ventures 团队) 与 Google 合作,在今年的 Google I/O 大会上推出了 照相亭互动体验 ( ...

  6. Expo大作战(十六)--expo结合firebase 一个nosql数据库(本章令我惊讶但又失望!)

    简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,讲全部来与官网 我猜去全部机翻+个人 ...

  7. GitHub没有实时通知怎么办?当然是自己上手写一个啊!

    相信各位程序员对github已经不陌生了.不知道各位有没有注意到GitHub没有推送通知这个功能.当有人在我的存储库中创建了一个提取请求/问题时,我可以收到电子邮件通知,但当有人stars/forks ...

  8. Google Material Design的图标字体使用教程

    使用教程 1. 打开Material icons下载页 2. 选择要下载的图标 (目前不能多选>_<) 3.选择要下载的格式即可 图标字体使用教程 [方法一] STEP 1: 引入字体文件 ...

  9. android 很多牛叉布局github地址(转)

    原文地址 http://blog.csdn.net/luo15309823081/article/details/41449929 点击可到达github-------https://github.c ...

随机推荐

  1. 利用zip格式实现手机客户端二维码扫描分享识别

    场景: 用户A想要将某应用推荐给用户B,用户B扫描用户A的手机app中的二维码进行下载和安装, 并且需要识别用户B是扫描了用户A的二维码,进而给用户A一定的奖励. (例如:健一网app) zip格式: ...

  2. Windows简单入门-送给第一次使用电脑的朋友

    序言 写本篇文章前.不得不说我已经好久没有写博客了,快接近3个月了 吧,本来去年说參加今年的博客之星的,结果这都立即结束了:不得不说对自己有些嘲讽. 本篇文章是纯小白文章.之所以写这个是由于前段时间妹 ...

  3. 负载均衡器&amp;http正向代理

    透明的负载均衡器&http正向代理 * master-workers架构,http正向代理由独立的dns请求以及缓冲进程  * 使用epoll(ET)模式,採用全异步方式(双缓存,实现双向同一 ...

  4. 洛谷P3374 【模板】树状数组 1(CDQ分治)

    题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某一个数加上x 2.求出某区间每一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. ...

  5. 记Bootstrap Table两种渲染方式

    这里主要区别两种Bootstrap Table的数据渲染方式,一.属性渲染方式,二.JS渲染方式 工作直接接手前人的,之前都直接在table标签上渲染属性,后面因为项目需要,同一页面的表格,需要申请不 ...

  6. CISP/CISA 每日一题 四

    CISA 每日一题(答) 连续在线审计技术: 1.系统控制审计检查文件和内嵌审计模型(SCARF/EAM):非常复杂,适用于正常处理不能被中断:通过在组织的主机应用系统中内嵌经特别编写的审计软件,使审 ...

  7. 【例题 8-7 UVA - 11572】Unique Snowflakes

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 类似尺取法. 用set判断这段区间有没有重复的数字. 有的话,就把头节点的那个数字删掉,直到没有为止. [代码] /* 1.Shou ...

  8. eclipse git冲突解决

    1.工程->Team->同步: 2.从远程pull至本地,就会出现如下内容: 3.使用Merge Tool,执行第二项 4.再手动修改 4.修改后的文件需要添加到Git index中去: ...

  9. WEB安全实战(二)带你认识 XSS 攻击

    前言 上一篇文章写了关于 WEB 安全方面的实战,主要是解决 SQL 盲注的安全漏洞.这篇文章本来是要写一篇关于怎样防治 XSS 攻击的,可是想来想去,还是决定先从理论上认识一下 XSS 吧.下一篇文 ...

  10. 为什么golang的开发效率高(编译型的强类型语言、工程角度高、在开发上的高效率主要来自于后发优势,编译快、避免趁编译时间找产品妹妹搭讪,既是强类型语言又有gc,只要通过编译,非业务毛病就很少了)

    作者:阿猫链接:https://www.zhihu.com/question/21098952/answer/21813840来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...