fireauth

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

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

Go to latest
Published: Sep 8, 2016 License: MIT Imports: 7 Imported by: 1

README

Fireauth


Build Status Coverage Status

A Firebase token generator written in Go

Installation

go get -u github.com/zabawaba99/fireauth

Usage

Import fireauth

import "github.com/zabawaba99/fireauth"

Create a TokenGenerator

gen := fireauth.New("foo")

Generate a token

data := fireauth.Data{"uid": "1"}
token, err := gen.CreateToken(data, nil)
if err != nil {
  log.Fatal(err)
}
println("my token: ",token)
Options

You can also create a token with options

data := fireauth.Data{"uid": "1"}
options := &fireauth.Option{
  NotBefore: 2,
  Expiration: 3,
  Admin: false,
  Debug: true,
}
token, err := gen.CreateToken(data, options)
if err != nil {
  log.Fatal(err)
}
println("my token: ",token)

Check the GoDocs or Firebase Auth Documentation for more details

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b new-feature)
  3. Commit your changes (git commit -am 'Some cool reflection')
  4. Push to the branch (git push origin new-feature)
  5. Create new Pull Request

Documentation

Index

Constants

View Source
const (
	// Version used for creating token
	Version = 0
	// TokenSep used as a delimiter for the token
	TokenSep = "."
	// MaxUIDLen is the maximum length for an UID
	MaxUIDLen = 256
)
View Source
const (
	TokenAlgorithm = "HS256"
	TokenType      = "JWT"
)

Firebase specific values for header

Variables

View Source
var (
	ErrNoUIDKey           = errors.New(`Data payload must contain a "uid" key`)
	ErrUIDNotString       = errors.New(`Data payload key "uid" must be a string`)
	ErrUIDTooLong         = errors.New(`Data payload key "uid" must not be longer than 256 characters`)
	ErrEmptyDataNoOptions = errors.New("Data is empty and no options are set.  This token will have no effect on Firebase.")
	ErrTokenTooLong       = errors.New("Generated token is too long. The token cannot be longer than 1024 bytes.")
)

Generic errors

Functions

This section is empty.

Types

type Data

type Data map[string]interface{}

Data is used to create a token. The token data can contain any data of your choosing, however it must contain a `uid` key, which must be a string of less than 256 characters

type Generator

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

Generator represents a token generator

func New

func New(secret string) *Generator

New creates a new Generator

func (*Generator) CreateToken

func (t *Generator) CreateToken(data Data, options *Option) (string, error)

CreateToken generates a new token with the given Data and options

type Option

type Option struct {
	// NotBefote is the token "not before" date as a number of seconds since the Unix epoch.
	// If specified, the token will not be considered valid until after this date.
	NotBefore int64 `json:"nbf,omitempty"`

	// Expiration is the token expiration date as a number of seconds since the Unix epoch.
	// If not specified, by default the token will expire 24 hours after the "issued at" date (iat).
	Expiration int64 `json:"exp,omitempty"`

	// Admin when set to true to make this an "admin" token, which grants full read and
	// write access to all data.
	Admin bool `json:"admin,omitempty"`

	// Debug when set to true to enable debug mode, which provides verbose error messages
	// when Security and Firebase Rules fail.
	Debug bool `json:"debug,omitempty"`
}

Option represent the claims used when creating an authentication token https://www.firebase.com/docs/rest/guide/user-auth.html#section-rest-tokens-without-helpers

Jump to

Keyboard shortcuts

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