model

package
v0.0.0-...-6d37592 Latest Latest
Warning

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

Go to latest
Published: May 24, 2017 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoKeyID returned if the JWT lacks a kid value in the header.
	ErrNoKeyID = errors.New("missing key ID in header")

	// ErrNoKey returned if the key ID is invalid (or expired).
	ErrNoKey = errors.New("invalid key ID")

	// ErrInvalidAlgorithm returned if the algorithm is the wrong type.
	ErrInvalidAlgorithm = errors.New("invalid algorithm")

	// ErrTokenExpired returned if the JWT has expired.
	ErrTokenExpired = errors.New("token expired")

	// ErrTokenUsedBeforeIssued returned if the token is used prematurely.
	ErrTokenUsedBeforeIssued = errors.New("token used before issued")
)
View Source
var (
	// UserDB mimics a database of users.
	UserDB = make(map[string]User)

	// ErrNotFound returned if the username is invalid.
	ErrNotFound = errors.New("user not found")
)

Functions

func DetermineKey

func DetermineKey(token *jwt.Token) (interface{}, error)

DetermineKey looks up the public key and confirms the algorithm.

Types

type JWTTime

type JWTTime struct {
	time.Time
}

JWTTime enforces JSON marshaling the time in seconds.

func (JWTTime) MarshalJSON

func (t JWTTime) MarshalJSON() ([]byte, error)

MarshalJSON marshals the time as a UNIX timestamp in seconds.

func (*JWTTime) UnmarshalJSON

func (t *JWTTime) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the data assuming an integer timestamp in seconds.

type User

type User struct {
	ID        string `json:"id"`
	Username  string `json:"username"`
	Email     string `json:"email"`
	FirstName string `json:"first_name,omitempty"`
	LastName  string `json:"last_name,omitempty"`
	Role      string `json:"role"`

	// Password won't be included with JSON response!
	Password string `json:"-"`

	// Issued indicates when the JWT token for this user was issued.
	Issued JWTTime `json:"iat,omitempty"`

	// Expires indicates when the JWT token for this user expires.
	Expires JWTTime `json:"exp,omitempty"`
}

User represents an authenticated user account.

func FindUser

func FindUser(username string) (User, error)

FindUser looks up a user by username.

func NewUser

func NewUser(username, password, email, first, last, role string) User

NewUser generates a new User object.

func VerifyUser

func VerifyUser(token string) (User, error)

VerifyUser validates and converts a JWT token.

func (User) Token

func (u User) Token() ([]byte, error)

Token generates a JWT token for the user, complete with institution information. Token will expire in one hour.

func (User) Valid

func (u User) Valid() error

Valid validates the JWT token expiration based issued time and expiration.

Jump to

Keyboard shortcuts

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