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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?