authtoken

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2016 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileStore

type FileStore string

FileStore implements TokenStore by saving users' Token under a directory specified by a string. Each access token is stored in a separate file.

func (FileStore) Delete

func (f FileStore) Delete(accessToken string) error

Delete removes the access token from the file store.

Delete return an error if the token cannot removed. It is NOT not an error if the token does not exist at deletion time.

func (FileStore) Get

func (f FileStore) Get(accessToken string, token *Token) error

Get tries to read the specified access token from file and writes to the supplied Token.

Get returns an NotFoundError if no such access token exists or such access token is expired. In the latter case the expired access token is still written onto the supplied Token.

func (FileStore) Init

func (f FileStore) Init() FileStore

Init MkAllDirs the FileStore directory and return itself.

It panics when it fails to create the directory.

func (FileStore) Put

func (f FileStore) Put(token *Token) error

Put writes the specified token into a file and overwrites existing Token if any.

type NotFoundError

type NotFoundError struct {
	AccessToken string
	Err         error
}

NotFoundError is the error returned by Get if a TokenStore cannot find the requested token or the fetched token is expired.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type RedisStore

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

RedisStore implements TokenStore by saving users' token in a redis server

func NewRedisStore

func NewRedisStore(address string) *RedisStore

func (*RedisStore) Delete

func (r *RedisStore) Delete(accessToken string) error

func (*RedisStore) Get

func (r *RedisStore) Get(accessToken string, token *Token) error

func (*RedisStore) Put

func (r *RedisStore) Put(token *Token) error

type RedisToken

type RedisToken struct {
	AccessToken string `redis:"accessToken"`
	ExpiredAt   int64  `redis:"expiredAt"`
	AppName     string `redis:"appName"`
	UserInfoID  string `redis:"userInfoID"`
}

RedisToken stores a Token with UnixNano timestamp

func (RedisToken) ToToken

func (r RedisToken) ToToken() *Token

type Store

type Store interface {
	Get(accessToken string, token *Token) error
	Put(token *Token) error
	Delete(accessToken string) error
}

Store represents a persistent storage for Token.

func InitTokenStore

func InitTokenStore(impl string, path string) Store

InitTokenStore accept a implementation and path string. Return a Store.

type Token

type Token struct {
	AccessToken string    `json:"accessToken" redis:"accessToken"`
	ExpiredAt   time.Time `json:"expiredAt" redis:"expiredAt"`
	AppName     string    `json:"appName" redis:"appName"`
	UserInfoID  string    `json:"userInfoID" redis:"userInfoID"`
}

Token is an expiry access token associated to a UserInfo.

func New

func New(appName string, userInfoID string, expiredAt time.Time) Token

New creates a new Token ready for use given a userInfoID and expiredAt date. If expiredAt is passed an empty Time, it will be set to 30 days from now.

func (*Token) IsExpired

func (t *Token) IsExpired() bool

IsExpired determines whether the Token has expired now or not.

func (Token) MarshalJSON

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

func (Token) ToRedisToken

func (t Token) ToRedisToken() *RedisToken

func (*Token) UnmarshalJSON

func (t *Token) UnmarshalJSON(data []byte) (err error)

Jump to

Keyboard shortcuts

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