gfa

package module
v0.0.0-...-dde8538 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2020 License: MIT Imports: 5 Imported by: 0

README

Gin-Firebase-Auth (GFA)

GFA is a package of gin middlewares to handle authentification using Google Firebase.

Setup

First, you need to initialize your firebase app. Once you have your app variable, create a new GFA config object:

config := gfa.Handler{}
config.Init(app) // Pass your firebase app variable.

gfaHandler will automatically declare some firebase objects to use inside middlewares.

Middlewares

Each gfa middlewares use a wrapper, to pass in some parameters. To declare them, use :

router.METHOD(
    path,
    mid(config, ...opts),
    ...
)

Each section comes with a how-to-use example, for better clarity.

VerifyToken
Option Type Description
nonRestrictivePolicy bool When authentication fails, the request is aborted with an unauthorized status.
Set this flag to true to override this behavior.

Go handles auth with credentials from its own api. Once an user is logged, each secure request will be issued with an Authorization header, containing a token id that handles credentials.

VerifyToken will check and decode this token.

package main

import "github.com/Alvarios/gin-firebase-auth"

func main() {
    // Set your gin and gfa apps here.
    
    router.GET(
        "/path/to/resource1",
        gfa.VerifyToken(config, false),
        GetResource1,   // Use your own functions here.
        Render,
    )
}

2020 Kushuh - MIT license

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifyToken

func VerifyToken(app *Handler, nonRestrictivePolicy bool) gin.HandlerFunc

Go handles auth with credentials from its own api. We just have to check for a valid token on secure routes.

Types

type Handler

type Handler struct {
	App  *firebase.App
	Auth *auth.Client
}

func (*Handler) Init

func (h *Handler) Init(app *firebase.App) error

Jump to

Keyboard shortcuts

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