jwt

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

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

Go to latest
Published: Sep 18, 2015 License: Apache-2.0 Imports: 7 Imported by: 0

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

func AuthRequest

func AuthRequest(o *Options) beego.FilterFunc

AuthRequest retunn FilterFunc

func CreateToken

func CreateToken() map[string]string

CreateToken return the token

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

type Options

type Options struct {
	PrivateKeyPath string
	PublicKeyPath  string
	WhiteList      []string
}

Options for the JWT Auth

Jump to

Keyboard shortcuts

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