fireauth: github.com/zabawaba99/fireauth Index | Files

package fireauth

import "github.com/zabawaba99/fireauth"

Index

Package Files

generator.go

Constants

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
)
const (
    TokenAlgorithm = "HS256"
    TokenType      = "JWT"
)

Firebase specific values for header

Variables

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

type Data Uses

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 Uses

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

Generator represents a token generator

func New Uses

func New(secret string) *Generator

New creates a new Generator

func (*Generator) CreateToken Uses

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

CreateToken generates a new token with the given Data and options

type Option Uses

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

Package fireauth imports 7 packages (graph) and is imported by 2 packages. Updated 2019-02-17. Refresh now. Tools for package owners.