firelogin

package module
v0.0.0-...-7f42e54 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2018 License: MIT Imports: 10 Imported by: 0

README

firelogin

Allows your Firebase users to authenticate in a CLI app.

Demo

Install the demo:

$ go install github.com/nouney/firelogin/demo

Run it:

$ $GOPATH/bin/demo
Your browser has been opened to visit: http://localhost:8080

Authentication successfull. Welcome, <your full name>.

Getting started

Install firelogin:

$ go get github.com/nouney/firelogin

Copy/paste the code below then run it:

package main

import (
	"fmt"
	"log"

	"github.com/nouney/firelogin"
)

func main() {
	flogin := firelogin.New(&firelogin.Config{
		APIKey:      "<YOUR FIREBASE API KEY>",
		AuthDomain:  "<YOUR FIREBASE AUTH DOMAIN>",
	})
	// This will block until the user sign in
	user, err := flogin.Login()
	if err != nil {
		log.Panic(err)
	}
	fmt.Println("Authentication successfull! Welcome,", user.DisplayName)
}

It will open a FirebaseUI webpage allowing you to authenticate.

Customization
FirebaseUI
package main

import (
	"fmt"
	"log"

	"github.com/nouney/firelogin"
)

func main() {
    // no providers = all
	ui := firelogin.NewFirebaseUI(
		"AppName", 
		firelogin.GITHUB_AUTH_PROVIDER_ID, 
		firelogin.GOOGLE_AUTH_PROVIDER_ID
	)
	flogin := firelogin.New(&firelogin.Config{
		APIKey:      "<YOUR FIREBASE API KEY>",
		AuthDomain:  "<YOUR FIREBASE AUTH DOMAIN>",
		URL: "https://your-domain.com/yourpage",
	})
	user, err := flogin.Login()
	if err != nil {
		log.Panic(err)
	}
	fmt.Println("Authentication successfull! Welcome,", user.DisplayName)
}

Documentation

Index

Constants

View Source
const (
	GOOGLE_AUTH_PROVIDER_ID   = "firebase.auth.GoogleAuthProvider.PROVIDER_ID"
	FACEBOOK_AUTH_PROVIDER_ID = "firebase.auth.FacebookAuthProvider.PROVIDER_ID"
	TWITTER_AUTH_PROVIDER_ID  = "firebase.auth.TwitterAuthProvider.PROVIDER_ID"
	GITHUB_AUTH_PROVIDER_ID   = "firebase.auth.GithubAuthProvider.PROVIDER_ID"
	EMAIL_AUTH_PROVIDER_ID    = "firebase.auth.EmailAuthProvider.PROVIDER_ID"
	PHONE_AUTH_PROVIDER_ID    = "firebase.auth.PhoneAuthProvider.PROVIDER_ID"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FirebaseUI

type FirebaseUI struct {
	// contains filtered or unexported fields
}

func NewFirebaseUI

func NewFirebaseUI(name string, providers ...string) *FirebaseUI

func (FirebaseUI) AuthHTML

func (fui FirebaseUI) AuthHTML() string

func (FirebaseUI) SuccessHTML

func (fui FirebaseUI) SuccessHTML() string

type Firelogin

type Firelogin struct {
	// contains filtered or unexported fields
}

func New

func New(apiKey, authDomain string, opts ...Opt) (*Firelogin, error)

New creates a new Firelogin instance apiKey and authDomain can be found in firebase.

func (*Firelogin) Login

func (f *Firelogin) Login() (*User, error)

Login logs an user in. This blocks until the user authenticates itself (success or fail)

func (*Firelogin) RenewAccessToken

func (f *Firelogin) RenewAccessToken(refreshToken string) (*User, error)

RenewAccessToken renews an access token from a refresh token

type Opt

type Opt func(f *Firelogin) error

func WithAuthHTML

func WithAuthHTML(h string) Opt

func WithPort

func WithPort(p string) Opt

func WithSuccessHTML

func WithSuccessHTML(h string) Opt

type User

type User struct {
	UID           string `json:"uid"`
	DisplayName   string `json:"displayName"`
	PhotoURL      string `json:"photoURL"`
	Email         string `json:"email"`
	EmailVerified bool   `json:"emailVerified"`
	IsAnonymous   bool   `json:"isAnonymous"`
	ProviderData  []struct {
		UID         string `json:"uid"`
		DisplayName string `json:"displayName"`
		PhotoURL    string `json:"photoURL"`
		Email       string `json:"email"`
		ProviderID  string `json:"providerId"`
	} `json:"providerData"`
	APIKey          string `json:"apiKey"`
	AppName         string `json:"appName"`
	AuthDomain      string `json:"authDomain"`
	StsTokenManager struct {
		APIKey         string `json:"apiKey"`
		RefreshToken   string `json:"refreshToken"`
		AccessToken    string `json:"accessToken"`
		ExpirationTime int64  `json:"expirationTime"`
	} `json:"stsTokenManager"`
	LastLoginAt string `json:"lastLoginAt"`
	CreatedAt   string `json:"createdAt"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL