Documentation ¶
Overview ¶
Package jwt provides JWT (Json Web Token) authentication
Usage In file main.go
import ( "github.com/astaxie/beego" "github.com/astaxie/beego/plugins/jwt"
)
func main() { // JWT for Url matching /v1/* // PrivateKeyPath: The path for the private RSA key used by JWT // PublicKeyPath: The path for the public RSA key used by JWT // The list of Urls should be excluded from the JWT Auth beego.InsertFilter("/v1/*", beego.BeforeRouter, jwt.AuthRequest(&jwt.Options{ PrivateKeyPath: "conf/beeblog.rsa", PublicKeyPath: "conf/beeblog.rsa.pub", WhiteList: []string{"/v1/jwt/issue-token", "/docs"}, })) beego.Run() }
In file routers/router.go
import ( "github.com/astaxie/beego" "github.com/astaxie/beego/plugins/jwt"
)
func init() { ns := beego.NSNamespace("/jwt", beego.NSInclude( &jwt.JwtController{}, ), ) beego.AddNamespace(ns) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RSAKeys struct { PrivateKey []byte PublicKey []byte }
RSAKeys store PrivateKey and PublicKey
Functions ¶
Types ¶
type Controller ¶
type Controller struct {
beego.Controller
}
Controller oprations for Jwt
func (*Controller) IssueToken ¶
func (c *Controller) IssueToken()
IssueToken function @Title IssueToken @Description Issue a Json Web Token @Success 200 string @Failure 403 no privilege to access @Failure 500 server inner error @router /issue-token [get]
func (*Controller) URLMapping ¶
func (c *Controller) URLMapping()
URLMapping is used to mapping the string to method
Click to show internal directories.
Click to hide internal directories.