vaper

package module
v0.0.0-...-13eadea Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2017 License: MIT Imports: 6 Imported by: 6

README

vaper

A library to turn structs into JWS or JWE.

Usage

To have struct fields show up in web tokens, tag them with token:"yourtokenfieldname".

import (
      "github.com/opsee/vaper"
)

type User struct {
	Id                 int       `token:"id"`
	Email              string    `token:"email"`
	CreatedAt          time.Time `token:"created_at"`
	Admin              bool      `token:"admin"`
	ThisFieldIsIgnored bool
}

user := &User{
  Id: 1,
  Email: "vapin@vape.it",
  CreatedAt: time.Now(),
  Admin: true,
}

now := time.Now()
exp := now.Add(time.Hour)
token := vaper.New(user, "vapin@vape.it", now, exp)
tokenString, err := token.Marshal()

// verify token string
err := vaper.Verify(tokenString)

// reify the token string
decoded, err := vaper.Unmarshal(tokenString)
user := &User{}
err = decoded.Reify(user)

TODO

NOTE: this will be a public project, so watch what you put in here.

A more correct api would be:

generator := vaper.New(alg, enc string, exp time.Duration)
token, err := generator.Token(user)
  • generator as its own struct
  • struct tag for subject field
  • configurable algorithms
  • configurable encryption
  • more robust reflection for number types
  • marshal into io.Writer
  • benchmarking
  • godoc

Documentation

Index

Constants

View Source
const (
	Algorithm  = jose.A128GCMKW
	Encryption = jose.A128GCM
)

Variables

This section is empty.

Functions

func Init

func Init(sharedKey []byte)

func Verify

func Verify(tokenString string) error

Types

type Token

type Token map[string]interface{}

func New

func New(thing interface{}, sub string, iat, exp time.Time) *Token

func Unmarshal

func Unmarshal(tokenString string) (*Token, error)

func (*Token) Marshal

func (token *Token) Marshal() (string, error)

func (*Token) Reify

func (token *Token) Reify(thing interface{}) error

Jump to

Keyboard shortcuts

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