auth

package
v0.0.0-...-30b6ba1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2014 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

The auth package provides functions and types for dealing with logins, account registration and user authentication (including XSRF protection).

Index

Constants

View Source
const (
	TokenFieldName = "xsrf_token"
)

Variables

View Source
var (
	ErrTokenNotFound = fmt.Errorf("token not found")
)

Errors returned from Token-related functions.

Functions

func SaltAndHash

func SaltAndHash(b []byte) string

SaltAndHash creates a SHA512 hash of a byte string salted with an internal array of random bytes.

func SaltAndHashString

func SaltAndHashString(s string) string

SaltAndHash creates a SHA512 hash of a string salted with an internal array of random bytes.

Types

type Token

type Token struct {
	// Cryptographically random bytes.
	Token []byte

	// The ID string of the user who requested the token.
	UserID string

	// The path of the request for which the token is valid.
	Path string

	// The time after which the token is no longer valid.
	Expiration time.Time
}

A Token is an unguessable challenge token sent along with requests to prevent CSRF attacks.

func NewToken

func NewToken(userID, path string, now time.Time) (*Token, error)

NewToken creates a new Token for a user making a request which will expire 1 hour after the given time.

func TokenForRequest

func TokenForRequest(c appengine.Context, userID, path string) (*Token, error)

TokenForRequest returns the stored auth token for a user request. If the token could not be found, returns ErrTokenNotFound.

func (*Token) Delete

func (t *Token) Delete(c appengine.Context)

Delete attempts to remove the token from the datastore.

func (*Token) Encode

func (t *Token) Encode() string

Encode returns an encoded string of the token, suitable for embedding in an HTML form.

func (*Token) Equals

func (t *Token) Equals(u *Token) bool

func (*Token) IsValid

func (t *Token) IsValid(encoded string, now time.Time) bool

IsValid returns true if the token's encoding matches the given encoded token and its expiration is not after now.

func (*Token) Store

func (t *Token) Store(c appengine.Context) error

Store persists a token into the datastore, and possibly an in-memory cache.

func (*Token) String

func (t *Token) String() string

Jump to

Keyboard shortcuts

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