tokenauth2beego

package module
Version: v0.0.0-...-bc71274 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2015 License: Apache-2.0 Imports: 11 Imported by: 0

README

Tokenauth2beego

使用github.com/ysqi/tokenauth给 Beego 写的 token 验证插件,支持多种方式验证。

安装

go get github.com/ysqi/tokenauth2beego

TokenAuth包介绍

具体信息请参考 TokenAuth Readme.md

功能

  • 支持原生 TokenAuth 包功能,具体见TokenAuth ReadeMe.md
  • 支持 HTTP Header 验证
  • 支持 HTTP Get,Post 等传参验证

TODO

  • 实现 Cookie Token验证
  • 实现 Beego ORM 维护多 Client 信息
  • 实现验证通过后Token信息传递

基础使用

import(
    "github.com/astaxie/beego"
    "github.com/ysqi/tokenauth2beego/o2o"
)

func main(){
    // authenticate every request
    beego.InsertFilter("*", beego.BeforeRouter, o2o.DefaultFileter())
    beego.Run()
}

在用户登录成功后写入 Token

token, err := o2o.Auth.NewSingleToken(userID,responseWriter)

示例1

在 Web 站点中当用户成功后通过 Token 进行权限验证(待提供)

示例2

下载站点资源时限制有效期限(待提供)

示例3

Beego API 应用通过Token进行权限验证(待提供)

示例4

多站点单点登录

LICENSE

该包在Apache Licence, Version 2.0协议下使用 (http://www.apache.org/licenses/LICENSE-2.0.html).

Documentation

Overview

Package auth provides handlers to enable basic auth support. Example:

import(
	"github.com/astaxie/beego"
	"github.com/ysqi/tokenauth2beego/o2o"
)

func main(){
	// authenticate every request
	beego.InsertFilter("*", beego.BeforeRouter, o2o.DefaultFileter())
	beego.Run()
}

Save and Get SingleToken Token:

token, err := o2o.Auth.NewSingleToken(userID)

Index

Constants

View Source
const (
	TokenFieldName = "access_token"
)

Variables

View Source
var (
	ERR_ServerError = tokenauth.ValidationError{Code: "-1", Msg: "System error , Please retry"}
	ERR_UserIDEmpty = tokenauth.ValidationError{Code: "41020", Msg: "UserID is empty"}
)
View Source
var (
	EnableCookie = false // Save token string to cookie if enableCookie=true.
)

Functions

This section is empty.

Types

type Automatic

type Automatic struct {
	TokenFunc  tokenauth.GenerateTokenString
	SecretFunc tokenauth.GenerateSecretString
}

func (*Automatic) CheckToken

func (a *Automatic) CheckToken(req *http.Request) (token *tokenauth.Token, err error)

Check User Token from reqeust. First find Authorization from reqeust hearder, Then find access_token from reqeust form field. Returns effective token or error.

func (*Automatic) ConvertoCookie

func (a *Automatic) ConvertoCookie(token *tokenauth.Token) *http.Cookie

Returns a Cookie, Create by token info.

func (*Automatic) ReturnFailueInfo

func (a *Automatic) ReturnFailueInfo(err error, ctx *context.Context)

Write error info to response and abort request. e.g. response body:

{"errcode":"41001","errmsg":"Token is emtpy"}

func (*Automatic) SetTokenString

func (a *Automatic) SetTokenString(token *tokenauth.Token, w http.ResponseWriter)

Save token string to Response Header and Cookie.

Source Files

Directories

Path Synopsis
Package one client with one more tokens.
Package one client with one more tokens.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL