authz

gin-authz is an authorization middleware for Gin

  • 所有者: gin-contrib/authz
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Authz

Build Status
codecov
Go Report Card
GoDoc
Join the chat at https://gitter.im/gin-gonic/gin

Authz is an authorization middleware for Gin, it's based on https://github.com/casbin/casbin.

Installation

go get github.com/gin-contrib/authz

Simple Example

package main

import (
    "net/http"

    "github.com/casbin/casbin"
    "github.com/gin-contrib/authz"
    "github.com/gin-gonic/gin"
)

func main() {
    // load the casbin model and policy from files, database is also supported.
    e := casbin.NewEnforcer("authz_model.conf", "authz_policy.csv")

    // define your router, and use the Casbin authz middleware.
    // the access that is denied by authz will return HTTP 403 error.
    router := gin.New()
    router.Use(authz.NewAuthorizer(e))
}

Documentation

The authorization determines a request based on {subject, object, action}, which means what subject can perform what action on what object. In this plugin, the meanings are:

  1. subject: the logged-on user name
  2. object: the URL path for the web resource like "dataset1/item1"
  3. action: HTTP method like GET, POST, PUT, DELETE, or the high-level actions you defined like "read-file", "write-blog"

For how to write authorization policy and other details, please refer to the Casbin's documentation.

Getting Help

License

This project is under MIT License. See the LICENSE file for the full license text.

主要指标

概览
名称与所有者gin-contrib/authz
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2017-05-29 03:39:49
推送于2025-06-09 14:53:36
最后一次提交2025-05-25 15:21:15
发布数7
最新版本名称v1.0.5 (发布于 )
第一版名称v0.0.1 (发布于 )
用户参与
星数785
关注者数11
派生数58
提交数111
已启用问题?
问题数8
打开的问题数0
拉请求数13
打开的拉请求数1
关闭的拉请求数58
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?