token

package
v0.0.0-...-4c53254 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2015 License: MIT Imports: 10 Imported by: 14

Documentation

Index

Constants

View Source
const (
	AuthTypeGuest          = "guest"           // 游客
	AuthTypeEmailPassword  = "email_password"  // 邮箱+密码
	AuthTypeEmailCheckCode = "email_checkcode" // 邮箱+校验码, 校验码推送到邮箱
	AuthTypePhonePassword  = "phone_password"  // 手机+密码
	AuthTypePhoneCheckCode = "phone_checkcode" // 手机+校验码, 校验码短信推送给手机
	AuthTypeOAuthQQ        = "oauth_qq"        // QQ oauth
	AuthTypeOAuthWechat    = "oauth_wechat"    // 微信 oauth
	AuthTypeOAuthWeibo     = "oauth_weibo"     // 微博 oauth
)

Variables

This section is empty.

Functions

func ExpirationAccess

func ExpirationAccess(timestamp int64) int64

func ExpirationRefresh

func ExpirationRefresh(timestamp int64) int64

func GetBindType

func GetBindType(AuthType string) (typ model.BindType, err error)

func NewTokenId

func NewTokenId() string

Types

type Token

type Token struct {
	SessionId         string `json:"sid"`         // 服务器索引 Session 的 key
	TokenId           string `json:"token_id"`    // token 的标识, 每次刷新 token 改变此值
	AuthType          string `json:"auth_type"`   // token 的认证类型
	ExpirationAccess  int64  `json:"exp_access"`  // 该 token 的过期时间; 0 表示永远有效
	ExpirationRefresh int64  `json:"exp_refresh"` // 刷新 token 的截至时间, 固定值, 不会变化; 0 表示永远有效

	Signatrue string `json:"-"` // 和客户端交互的 token 签名部分; 在 Token.Encode 或者 Token.Decode 才会获取到正确的值
}

客户端访问 API 的令牌, 客户端和服务器交互的数据结构

func (*Token) Decode

func (token *Token) Decode(tokenBytes []byte) error

trim(url_base64(json(token))) + "." + hex(hmac-sha256(base64_str))

func (*Token) Encode

func (token *Token) Encode() ([]byte, error)

trim(url_base64(json(token))) + "." + hex(hmac-sha256(base64_str))

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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