Package: auth
RESTful, Simple Authorization system with ZERO configuration.What is Auth?Auth is a module that makes authorization simple and also scalable and powerful.  It also has a beautiful RESTful API for use in micro-service architectures and platforms.  It is originally desinged to use in Appido, a scalable media market in Iran.It supports Python2.6+ and if you have a mongodb backbone, you need ZERO configurations steps.  Just typeauth-serverand press enter!I use Travis and Codecov to keep myself honest.requirementsYou need to access tomongodb.  If you are using a remote mongodb,  provide these environment variables:MONGO_HOSTandMONGO_PORTInstallationpipinstallauthShow me an exampleok, lets image you have two users,JackandSara.  Sara can cook and Jack can dance. Both can laugh.You also need to choose a secret key for your application.  Because you may want to use Auth in various tools and each must have a secret key for seperating their scope.my_secret_key="pleaSeDoN0tKillMyC_at"fromauthimportAuthorizationcas=Authorization(my_secret_key)Now, Lets add 3 groups, Cookers, Dancers and Laughers.  Remember that groups are Roles.  So when we create a group, indeed we create a role:cas.add_group('cookers')cas.add_group('dancers')cas.add_group('laughers')Ok, great. You have 3 groups and you need to authorize them to do special things.cas.add_permission('cookers','cook')cas.add_permission('dancers','dance')cas.add_permission('laughers','laugh')Good.  You let cookers to cook and dancers to dance etc…
The final part is to set memberships for Sara and Jack:cas.add_membership('sara','cookers')cas.add_membership('sara','laughers')cas.add_membership('jack','dancers')cas.add_membership('jack','laughers')That’s all we need.  Now lets ensure that jack can dance:ifcas.user_has_permission('jack','dance'):print('YES!!! Jack can dance.')Authirization Methodsuse pydoc to see all methods:pydocauth.AuthorizationRESTful APILets run the server on port 4000:fromauthimportapi,serveserve('localhost',4000,api)Or, from version 0.1.2+ you can use this command:auth-serverSimple! Authorization server is ready to use.You can use it via simple curl or using mighty Requests module.  So in you remote application, you can do something like this:importrequestssecret_key="pleaSeDoN0tKillMyC_at"auth_api="http://127.0.0.1:4000/api"Lets create admin group:requests.post(auth_api+'/role/'+secret_key+'/admin')And lets make Jack an admin:requests.post(auth_api+'/permission/'+secret_key+'/jack/admin')And finally let’s check if Sara still can cook:requests.get(auth_api+'/has_permission/'+secret_key+'/sara/cook')RESTful API helpersauth comes with a helper class that makes your life easy.fromauth.clientimportClientservice=Client('srv201','http://192.168.99.100:4000')print(service)service.get_roles()service.add_role(role='admin')API Methodspydocauth.CAS.REST.service/ping[GET]Ping API, useful for your monitoring tools/api/membership/{KEY}/{user}/{role}[GET/POST/DELETE]Adding, removing and getting membership information./api/permission/{KEY}/{role}/{name}[GET/POST/DELETE]Adding, removing and getting permissions/api/has_permission/{KEY}/{user}/{name}[GET]Getting user permission info/api/role/{KEY}/{role}[GET/POST/DELETE]Adding, removing and getting roles/api/which_roles_can/{KEY}/{name}[GET]For example:  Which roles can send_mail?/api/which_users_can/{KEY}/{name}[GET]For example:  Which users can send_mail?/api/user_permissions/{KEY}/{user}[GET]Get all permissions that a user has/api/role_permissions/{KEY}/{role}[GET]Get all permissions that a role has/api/user_roles/{KEY}/{user}[GET]Get roles that user assinged to/api/roles/{KEY}[GET]Get all available rolesDeploymentDeploying Auth module in production environment is easy:gunicornauth:apiDockerizingIt’s simple:dockerbuild-tpython/auth-serverhttps://raw.githubusercontent.com/ourway/auth/master/Dockerfiledockerrun--name=auth-eMONGO_HOST='192.168.99.100'-p4000:4000-d--restart=always--link=mongodb-serverpython/auth-serverCopyrightFarsheed Ashouri@DocumentationFeel free to dig into source code.  If you think you can improve the documentation, please do so and send me a pull request.Unit Tests and CoverageI am trying to add tests as much as I can, but still there are areas that need improvement.To DOAdd Authentication featuresImprove Code Coverage