1
0
mirror of https://github.com/labstack/echo.git synced 2025-12-03 22:59:09 +02:00

New name for repo

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana
2015-03-27 14:21:30 -07:00
parent 827177a814
commit 064a69d1dc
13 changed files with 51 additions and 352 deletions

View File

@@ -6,24 +6,24 @@ import (
"strings"
"github.com/dgrijalva/jwt-go"
"github.com/labstack/bolt"
"github.com/labstack/echo"
)
type (
BasicAuthFunc func(string, string) bool
AuthorizedHandler bolt.HandlerFunc
UnauthorizedHandler func(*bolt.Context, error)
AuthorizedHandler echo.HandlerFunc
UnauthorizedHandler func(*echo.Context, error)
JwtKeyFunc func(string) ([]byte, error)
Claims map[string]interface{}
)
var (
ErrBasicAuth = errors.New("bolt: basic auth error")
ErrJwtAuth = errors.New("bolt: jwt auth error")
ErrBasicAuth = errors.New("echo: basic auth error")
ErrJwtAuth = errors.New("echo: jwt auth error")
)
func BasicAuth(ah AuthorizedHandler, uah UnauthorizedHandler, fn BasicAuthFunc) bolt.HandlerFunc {
return func(c *bolt.Context) {
func BasicAuth(ah AuthorizedHandler, uah UnauthorizedHandler, fn BasicAuthFunc) echo.HandlerFunc {
return func(c *echo.Context) {
auth := strings.Fields(c.Request.Header.Get("Authorization"))
if len(auth) == 2 {
scheme := auth[0]
@@ -44,8 +44,8 @@ func BasicAuth(ah AuthorizedHandler, uah UnauthorizedHandler, fn BasicAuthFunc)
}
}
func JwtAuth(ah AuthorizedHandler, uah UnauthorizedHandler, fn JwtKeyFunc) bolt.HandlerFunc {
return func(c *bolt.Context) {
func JwtAuth(ah AuthorizedHandler, uah UnauthorizedHandler, fn JwtKeyFunc) echo.HandlerFunc {
return func(c *echo.Context) {
auth := strings.Fields(c.Request.Header.Get("Authorization"))
if len(auth) == 2 {
t, err := jwt.Parse(auth[1], func(token *jwt.Token) (interface{}, error) {