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. Linux运维命令总结

    .什么是运维?什么是游戏运维? 1)运维是指大型组织已经建立好的网络软硬件的维护,就是要保证业务的上线与运作的正常, 在他运转的过程中,对他进行维护,他集合了网络.系统.数据库.开发.安全.监控于一身 ...

  2. double 失真例子

    public static void main(String[] args) {  // TODO Auto-generated method stub  double ab=821.20;  dou ...

  3. 火狐—火狐浏览器中的“HttpWatch”

    在IE下通过HttpWatch能够查看HTTP请求的相关细节.这对我们分析程序的运行效率很有帮助,但是在火狐浏览器中的难道就没有相似的工具了吗?答案是否定的--火狐浏览器中也有.在火狐浏览器中该工具叫 ...

  4. 非对称算法,散列(Hash)以及证书的那些事

    转载请注明出处 http://blog.csdn.net/pony_maggie/article/details/35389657 作者:小马 这几个概念在金融电子支付领域用得比較多,我忽然认为把它们 ...

  5. 取消xp开机默认登陆账户

    取消xp开机默认登陆账户 建了个新用户,把以前的用户删除后重新启动电脑,始终停留在 "正在启动" 界面,网上说是 Event Log:Eventlog(系统日志纪录服务) 没有自动 ...

  6. thinkphp杂项功能(主干)

    thinkphp杂项功能(主干) 一.总结 1.杂项功能:杂项里面我需要有点印象的是五个:缓存,多语言,图像处理,文件处理,单元测试 二.thinkphp杂项功能(主干) thinkphp扩展杂项功能 ...

  7. 在Sql中将 varchar 值 '1,2,3,4,5,6' 转换成数据类型 int

    --问题:将aa转换为Int类型失败 string aa="3,5,11,56,88,45,23"; select * from ERPBuMen where ID in(aa) ...

  8. F的ACM暑期集训计划

    暑假的知识计划(补充中...) 1.数论相关 (7days) 待完成 多项式同余方程/高次同余方程/欧拉函数/克莱姆法则/高斯消元/莫比乌斯反演/伪素数判定/baby-step-gaint-step ...

  9. C#之使用app.config可记录数据,下次打开可读取记录的数据

    一.背景 如下图所示,我通过open..按键打开了某个文件,之后我再把app给关闭掉,当再次打开app的时候,在textBox.Text上显示上一次打开的文件路径.通过使用app.config可以保存 ...

  10. Visual Studio Team Services持续集成到Github仓库

    Devops如何用VSTS持续集成到Github仓库!   工欲善其事,必先利其器.在开始正式的教程之前我们先来聊聊准备工作. 管理工具会VSTS. 代码管理会用GITHUB. 服务器会用Azure. ...