{"id":20347094,"url":"https://github.com/ourway/auth","last_synced_at":"2025-07-27T13:10:26.896Z","repository":{"id":57412617,"uuid":"44346686","full_name":"ourway/auth","owner":"ourway","description":"Authorization for humans","archived":false,"fork":false,"pushed_at":"2023-04-24T18:58:51.000Z","size":129,"stargazers_count":52,"open_issues_count":0,"forks_count":10,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-12-09T06:32:18.686Z","etag":null,"topics":["authorization","python","python-library","roles"],"latest_commit_sha":null,"homepage":"http://auth.readthedocs.org/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ourway.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-15T21:29:21.000Z","updated_at":"2024-08-22T02:03:32.000Z","dependencies_parsed_at":"2024-06-19T00:03:46.357Z","dependency_job_id":"08178279-e526-417a-baee-35c318fbcd4b","html_url":"https://github.com/ourway/auth","commit_stats":{"total_commits":67,"total_committers":6,"mean_commits":"11.166666666666666","dds":"0.22388059701492535","last_synced_commit":"f0d9676854dcec494add4fa086a9b2a3e4d8cea5"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ourway%2Fauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ourway%2Fauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ourway%2Fauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ourway%2Fauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ourway","download_url":"https://codeload.github.com/ourway/auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230400606,"owners_count":18219830,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authorization","python","python-library","roles"],"created_at":"2024-11-14T22:15:19.753Z","updated_at":"2024-12-19T08:07:47.581Z","avatar_url":"https://github.com/ourway.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"====================================\nAuth | Authorization for Humans\n====================================\n\nRESTful, Simple Authorization system with ZERO configuration.\n\n.. image:: https://badge.fury.io/py/auth.svg\n    :target: https://badge.fury.io/py/auth\n\n.. image:: https://img.shields.io/pypi/dm/auth.svg\n    :target: https://pypi.python.org/pypi/auth\n\n\n\n\n.. image:: https://api.travis-ci.org/ourway/auth.svg\n    :target: https://travis-ci.org/ourway/auth\n\n.. image:: https://codecov.io/github/ourway/auth/coverage.svg?branch=master\n    :target: https://codecov.io/github/ourway/auth?branch=master\n\n\n\n\n***************\nWhat is Auth?\n***************\nAuth 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.\n\nIt supports Python2.6+ and if you have a mongodb backbone, you need ZERO configurations steps.  Just type ``auth-server`` and press enter!\n\nI use Travis and Codecov to keep myself honest.\n\n*******************\nrequirements\n*******************\n\nYou need to access to **mongodb**.  If you are using a remote mongodb,  provide these environment variables:\n\n``MONGO_HOST`` and ``MONGO_PORT``\n\n\n*******************\nInstallation\n*******************\n\n.. code:: Bash\n\n    pip install auth\n\n\n*******************\nShow me an example\n*******************\nok, lets image you have two users, **Jack** and **Sara**.  Sara can cook and Jack can dance. Both can laugh.\n\nYou 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.\n\n.. code:: Python\n\n    my_secret_key = \"pleaSeDoN0tKillMyC_at\"\n    from auth import Authorization\n    cas = Authorization(my_secret_key)\n\nNow, Lets add 3 groups, Cookers, Dancers and Laughers.  Remember that groups are Roles.  So when we create a group, indeed we create a role:\n\n.. code:: Python\n\n    cas.add_group('cookers')\n    cas.add_group('dancers')\n    cas.add_group('laughers')\n\n\nOk, great. You have 3 groups and you need to authorize them to do special things.\n\n.. code:: Python\n\n    cas.add_permission('cookers', 'cook')\n    cas.add_permission('dancers', 'dance')\n    cas.add_permission('laughers', 'laugh')\n\n\nGood.  You let cookers to cook and dancers to dance etc...\nThe final part is to set memberships for Sara and Jack:\n\n.. code:: Python\n\n    cas.add_membership('sara', 'cookers')\n    cas.add_membership('sara', 'laughers')\n    cas.add_membership('jack', 'dancers')\n    cas.add_membership('jack', 'laughers')\n\n\n\nThat's all we need.  Now lets ensure that jack can dance:\n\n.. code:: Python\n\n    if cas.user_has_permission('jack', 'dance'):\n        print('YES!!! Jack can dance.')\n\n\n\n**********************\nAuthorization Methods\n**********************\n\nuse pydoc to see all methods:\n\n.. code:: Bash\n\n    pydoc auth.Authorization\n\n\n*******************\nRESTful API\n*******************\nLets run the server on port 4000:\n\n.. code:: Python\n\n    from auth import api, serve\n    serve('localhost', 4000, api)\n\nOr, from version 0.1.2+ you can use this command:\n\n.. code:: Bash\n\n    auth-server\n\n\nSimple! Authorization server is ready to use.\n\n.. image:: https://raw.githubusercontent.com/ourway/auth/master/docs/API_Usage_Teminal.gif\n\n\nYou can use it via simple curl or using mighty Requests module.  So in you remote application, you can do something like this:\n\n.. code:: Python\n\n    import requests\n    secret_key = \"pleaSeDoN0tKillMyC_at\"\n    auth_api = \"http://127.0.0.1:4000/api\"\n\n\nLets create admin group:\n\n.. code:: Python\n\n    requests.post(auth_api+'/role/'+secret_key+'/admin')\n\n\nAnd lets make Jack an admin:\n\n.. code:: Python\n\n    requests.post(auth_api+'/permission/'+secret_key+'/jack/admin')\n\nAnd finally let's check if Sara still can cook:\n\n.. code:: Python\n\n    requests.get(auth_api+'/has_permission/'+secret_key+'/sara/cook')\n\n\n\n********************\nRESTful API helpers\n********************\nauth comes with a helper class that makes your life easy.\n\n.. code:: Python\n\n    from auth.client import Client\n    service = Client('srv201', 'http://192.168.99.100:4000')\n    print(service)\n    service.get_roles()\n    service.add_role(role='admin')\n\n\n*******************\nAPI Methods\n*******************\n\n\n.. code:: Bash\n\n    pydoc auth.CAS.REST.service\n\n\n\n\n- ``/ping`` [GET]\n\n\n Ping API, useful for your monitoring tools\n\n\n- ``/api/membership/{KEY}/{user}/{role}`` [GET/POST/DELETE]\n\n Adding, removing and getting membership information.\n\n\n- ``/api/permission/{KEY}/{role}/{name}`` [GET/POST/DELETE]\n\n Adding, removing and getting permissions\n\n\n- ``/api/has_permission/{KEY}/{user}/{name}`` [GET]\n\n Getting user permission info\n\n\n- ``/api/role/{KEY}/{role}`` [GET/POST/DELETE]\n\n  Adding, removing and getting roles\n\n\n- ``/api/which_roles_can/{KEY}/{name}`` [GET]\n\n  For example:  Which roles can send_mail?\n\n\n- ``/api/which_users_can/{KEY}/{name}`` [GET]\n\n  For example:  Which users can send_mail?\n\n\n- ``/api/user_permissions/{KEY}/{user}`` [GET]\n\n  Get all permissions that a user has\n\n- ``/api/role_permissions/{KEY}/{role}`` [GET]\n\n  Get all permissions that a role has\n\n\n- ``/api/user_roles/{KEY}/{user}`` [GET]\n\n    Get roles that user assinged to\n\n- ``/api/roles/{KEY}`` [GET]\n\n    Get all available roles\n\n\n*******************\nDeployment\n*******************\n\nDeploying Auth module in production environment is easy:\n\n\n.. code:: Bash\n\n    gunicorn auth:api\n\n\n\n\n*******************\nDockerizing\n*******************\n\nIt's simple:\n\n.. code:: Bash\n\n    docker build -t python/auth-server https://raw.githubusercontent.com/ourway/auth/master/Dockerfile\n    docker run --name=auth -e MONGO_HOST='192.168.99.100' -p 4000:4000 -d --restart=always --link=mongodb-server python/auth-server\n\n\n\n*******************\nCopyright\n*******************\n\n- Farsheed Ashouri `@ \u003cmailto:rodmena@me.com\u003e`_\n\n\n*******************\nDocumentation\n*******************\nFeel free to dig into source code.  If you think you can improve the documentation, please do so and send me a pull request.\n\n************************\nUnit Tests and Coverage\n************************\nI am trying to add tests as much as I can, but still there are areas that need improvement.\n\n\n**********\nTo DO\n**********\n- Add Authentication features\n- Improve Code Coverage\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fourway%2Fauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fourway%2Fauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fourway%2Fauth/lists"}