permission

package
v0.0.0-...-17112b8 Latest Latest
Warning

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

Go to latest
Published: May 6, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CasbinMiddleware = func(ctx *context.Context) {
	Authorization := ctx.Input.Header("Authorization")
	token := strings.Split(Authorization, " ")
	t, _ := jwt.Parse(token[1], func(*jwt.Token) (interface{}, error) {
		return Jwt.JwtSecret, nil
	})
	fmt.Println("req path", Jwt.GetIdFromClaims("username", t.Claims), ctx.Request.URL.Path, ctx.Request.Method)

	if b, err := inject.Obj.Enforcer.EnforceSafe(Jwt.GetIdFromClaims("username", t.Claims), ctx.Request.URL.Path, ctx.Request.Method); err != nil {
		fmt.Println("err", err)
		fmt.Println(b)
		Jwt.ResponseWithJson(ctx.ResponseWriter, http.StatusUnauthorized,
			Jwt.Response{Code: http.StatusOK, Msg: "ok", Data: err})
		return

	} else if !b {
		fmt.Println("err", err)
		fmt.Println(b)
		fmt.Println(ctx.ResponseWriter, http.StatusUnauthorized, http.StatusForbidden, "无权限", err)
		Jwt.ResponseWithJson(ctx.ResponseWriter, http.StatusUnauthorized,
			Jwt.Response{Code: http.StatusForbidden, Msg: "无权限", Data: err})
		return
	}

}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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