a simple authorization API for Python.

moat的Python项目详细描述


一个简单的python授权api。

示例

首先,将USEMIXIN和RealCyMyXin与您的用户类和 要为其提供授权的资源。

frommoatimportResourceMixin,UserMixinclassPost(ResourceMixin):deftype(self):returnself.__class__.__name__defidentifier(self):returnself.idclassUser(UserMixin):defidentifier(self):returnself.id

现在实现在基本存储库类中指定的方法来检索 数据存储的权限。传入存储库的实例 去主护城河班。

现在,您可以检查用户是否实际被授权执行某些操作:

frommoatimportMoat,Permissionsfrommoat.repositoriesimportMockRepositorymoat=Moat(MockRepository())# Now you can check if a user has a specific permission for a certain object.moat.has(Permission.read,user,post)moat.has(Permission.write,user,post)# Remove the permissionmoat.remove(Permission.write,user,post)# Set the permission, againmoat.set(Permission.write,user,post)# Or get all the ids of type of resources the user has permissions formoat.all(Permission.read,user,Post)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
playframework Play Framework 2.5表单对象bean(Java)中的依赖项注入   java从javascript触发小程序按钮   JavaGWT:如何创建我自己的异步方法?   对于JTA事务类型,java JPA更改不会持久化   java如何使用预定义的甲板类制作Black Jack游戏   带有数组的java HashMap find()   从Java中的另一个类接收对象数组的参数?   java IntelliJ错误:Scala 145,错误:scalac:找不到Scala编译器JAR   java Eclipse 404请求的资源不可用   java Chuck没有界限   java阅读行每隔一行跳过一行   java如何访问我的EAR部署信息   Java中的正则表达式,其中执行搜索的文本是动态变化的   java我需要优化BigInteger的toString()方法   java Google Map Api V2,自定义路线标记   java如何在Java8中与LocalDate实现更少的需求和更高的质量   EclipseUML插件生成Java源代码   将数据库列绑定到java jComboBox和JList   java如何将两个图像合并为PDF