{"id":15019276,"url":"https://github.com/shanathvemula/test_oauth2","last_synced_at":"2026-01-23T20:41:27.628Z","repository":{"id":241869883,"uuid":"808080340","full_name":"shanathvemula/test_oauth2","owner":"shanathvemula","description":"This repository provides a succinct overview of implementing OAuth2 authentication within Django, emphasizing its seamless integration with the User, Group, Permission, and ContentTypes APIs.","archived":false,"fork":false,"pushed_at":"2024-05-30T10:54:44.000Z","size":80,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-24T09:36:52.680Z","etag":null,"topics":["authentication","django","django-admin","django-application","django-framework","django-oauth-toolkit","django-project","django-rest-framework","djangorestframework","oauth2","oauth2-server","openid-provider","openid-server","permissions","python","python3","rest","rest-api","restful-api","roles"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shanathvemula.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-05-30T10:45:12.000Z","updated_at":"2024-06-19T19:07:25.000Z","dependencies_parsed_at":"2024-05-30T12:25:16.730Z","dependency_job_id":"7f32565d-6d71-4855-9387-085cd054a00c","html_url":"https://github.com/shanathvemula/test_oauth2","commit_stats":null,"previous_names":["shanathvemula/test_oauth2"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shanathvemula/test_oauth2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanathvemula%2Ftest_oauth2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanathvemula%2Ftest_oauth2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanathvemula%2Ftest_oauth2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanathvemula%2Ftest_oauth2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shanathvemula","download_url":"https://codeload.github.com/shanathvemula/test_oauth2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shanathvemula%2Ftest_oauth2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28699717,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T17:25:48.045Z","status":"ssl_error","status_checked_at":"2026-01-23T17:25:47.153Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["authentication","django","django-admin","django-application","django-framework","django-oauth-toolkit","django-project","django-rest-framework","djangorestframework","oauth2","oauth2-server","openid-provider","openid-server","permissions","python","python3","rest","rest-api","restful-api","roles"],"created_at":"2024-09-24T19:53:15.587Z","updated_at":"2026-01-23T20:41:27.606Z","avatar_url":"https://github.com/shanathvemula.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OAuth2 \n\n## Setup\n\nThe first thing to do is to clone the repository:\n\n```shell\ngit clone https://github.com/shanathvemula/test_oauth2.git\ncd test_oauth2\n```\n\nCreate a virtual environment to install dependencies in and activate it:\n\n```shell\n# Creating virtual environment\npython -m venv venv\n\n# In cmd.exe\nvenv\\Scripts\\activate.bat\n```\n\nThen install the dependencies:\n\n```shell\n(venv)$ pip install -r requirements.txt\n```\n\nNote the `(venv)` in front of the prompt. This indicates that this terminal\nsession operates in a virtual environment set up by `venv`.\n\nOnce `pip` has finished downloading the dependencies. \n\nDefault it will connect sqlite3 database.\nFor connecting Postgresql\n\n#### * Open settings.py in test_oauth2 folder\n\nRemove :\n\n```shell\nDATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.sqlite3',\n        'NAME': BASE_DIR / 'db.sqlite3',\n    }\n}\n```\nAdd:\n```shell\nDATABASES = {\n    'default': {\n        'ENGINE': 'django_tenants.postgresql_backend',\n        'NAME': '\u003cDatabase Name\u003e',\n        'USER': '\u003cpostgres username\u003e',\n        'PASSWORD': '\u003cpostgres password\u003e',\n        'HOST': '\u003cpostgres host address\u003e',\n        'PORT': \u003cpostgres port\u003e\n    }\n}\n```\nRun this commands in CMD:\n```shell\n(venv)$ python manage.py makemigrations\n(venv)$ python manage.py migrate\n(venv)$ python manage.py createsuperuser\nUsername (leave blank to use '---'): \u003cEnter username\u003e\nEmail address:\u003cEnter email address\u003e\nPassword: \u003cEnter Password\u003e\nPassword (again): \u003cEnter Password Again\u003e\n(venv)$ python manage.py runserver\n```\n\nAnd navigate to http://127.0.0.1:8000.\n\nEndpoints:\n```shell\n1. admin/\n2. o/\n3. contenttypes/\n4. permissions/\n5. groups/\n6. groups/\u003cpk\u003e\n7. user_list/\n8. user_create/\n9. users/\u003cusername\u003e\n10. check_permission/\n```\n\n## 1. admin/\n\nAdmin Panel\nhttp://127.0.0.1:8000/admin\n\n![img.png](static/README/admin.png)\n\n* To Login into Admin Panel\n\n## 2. o/\nAuthorization Endpoints\n\n### I. applications/\n\n* This endpoint is helps to create applications. you create application using this link http://127.0.0.1:8000/o/applications/ \n* If you want to create the application before you need to log in admin panel\n\n![img.png](static/README/CreateApplication.png)\n\n* Click on the `click here` link\n\n![img.png](static/README/CreateApplication1.png)\n\n* Here need to save the `Client id\n, Client secret` for the token generation.\n  \n* You need to enter name\n* select Client type as `Confidential`\n* select Authorization grant type as `Resource owner password-based` \n* Once we have clicked the save button. Client secret key will be hash.\n* Click save button\n\n![img.png](static/README/Application.png)\n\n\n### II. token\n\n* To get the access token.\n* Here we need to utilize the client_id, client_secret \n\n```shell\nURL : http://127.0.0.1:8000/o/token/\nRequest Method: POST\npayload:\n  grant_type = password\n  username = \u003cusername\u003e\n  password = \u003cpassword\u003e\n  client_id = \u003cclient_id\u003e\n  client_secret = \u003cclient_secret\u003e\n```\n\nExample cURL Code:\n```shell\ncurl --location 'http://127.0.0.1:8000/o/token/' \\\n--header 'Content-Type: application/x-www-form-urlencoded' \\\n--data-urlencode 'grant_type=password' \\\n--data-urlencode 'username=\u003cusername\u003e' \\\n--data-urlencode 'password=\u003cpassword\u003e' \\\n--data-urlencode 'client_id=PkKyETl9a98VCTxR4b2jMBwGQNjnGRSizFCdOGvl' \\\n--data-urlencode 'client_secret=cgyKqn2NG3ys5Dp7WcoliDadw858cUxUlAiZ2TGnrzGrSHes6aa3fxd0hNGi4YRGWnd1SFy6xhM57ycAzkMr2gd8lVytyN9Ea1Soc6qIfEH89CsrksoiO6thq1FEMfHn'\n```\n\nExample Output:\n\n```shell\n{\n    \"access_token\": \"UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\",\n    \"expires_in\": 36000,\n    \"token_type\": \"Bearer\",\n    \"scope\": \"read write groups\",\n    \"refresh_token\": \"hqhPDjmsTs9l92ILdKaHl25vx6FO0y\"\n}\n```\n\n* This access_token is used for the Authorization\n* Need to pass the access_token in headers like below\n    \n        Authorization: Bearer \u003caccess_token\u003e\n\n## 3. contenttypes/\n\n* This endpoint helps to List and create the Content Types\n\n### I. Listing Content Types\n\n* Getting list of Content Types\n\n```shell\nURL : http://127.0.0.1:8000/contenttypes/\nRequest Method: GET\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\n```\n\nExample cURL Code:\n\n```shell\ncurl --location 'http://127.0.0.1:8000/contenttypes/' \\\n--header 'Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ'\n```\n\n### II. Creating Content Types\n\n* Creating a Content Types\n\n```shell\nURL : http://127.0.0.1:8000/contenttypes/\nRequest Method: POST\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\npayload:\n  {\n    \"app_label\": \"\u003cApp Label\u003e\",\n    \"model\": \"\u003cmodel\u003e\",\n}\n```\n\nExample cURL Code:\n\n```shell\ncurl --location 'http://127.0.0.1:8000/contenttypes/' \\\n--header 'Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ' \\\n--header 'Content-Type: application/json' \\\n--data '{\n    \"app_label\": \"\u003cApp Label\u003e\",\n    \"model\": \"\u003cmodel\u003e\",\n}'\n```\n## 4. permissions/\n\n* This endpoint helps to List and create the Permissions\n\n### I. Listing Permissions\n\n* Getting list of Permissions\n\n```shell\nURL : http://127.0.0.1:8000/permissions/\nRequest Method: GET\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\n```\n\nExample cURL Code:\n\n```shell\ncurl --location 'http://127.0.0.1:8000/permissions/' \\\n--header 'Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ'\n```\n\n### II. Creating Permissions\n\n* Creating a Permission\n\n```shell\nURL : http://127.0.0.1:8000/permissions/\nRequest Method: POST\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\npayload:\n  {\n    \"name\": \"\u003cPermission Name\u003e\",\n    \"codename\": \"\u003cPermission codename\u003e\",\n    \"content_type\": \u003cContent Type Id\u003e\n}\n```\n\nExample cURL Code:\n\n```shell\ncurl --location 'http://127.0.0.1:8000/permissions/' \\\n--header 'Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ' \\\n--header 'Content-Type: application/json' \\\n--data '{\n    \"name\": \"\u003cPermission Name\u003e\",\n    \"codename\": \"\u003cPermission codename\u003e\",\n    \"content_type\": \u003cContent Type Id\u003e\n}'\n```\n## 5. groups\n\n* This endpoint helps to List and create the Group(Role)\n\n### I. Listing Groups\n\n* Getting list of Groups(Roles)\n\n```shell\nURL : http://127.0.0.1:8000/groups/\nRequest Method: GET\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\n```\n\nExample cURL Code:\n\n```shell\ncurl --location 'http://127.0.0.1:8000/groups/' \\\n--header 'Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ'```\n```\n\n* The Output will be List of Groups or Roles\n\n### II.Creating Group\n\n* Creating a Group or Role\n\n```shell\nURL : http://127.0.0.1:8000/groups/\nRequest Method: POST\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\npayload:\n  {\n    \"name\": \"\u003cName of Group\u003e\",\n    \"permissions\": []\n}\n```\nExample cURL Code:\n\n```shell\ncurl --location 'http://127.0.0.1:8000/groups/' \\\n--header 'Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ' \\\n--header 'Content-Type: application/json' \\\n--data '{\n    \"name\": \"\u003cName of Group\u003e\",\n    \"permissions\": []\n}'\n```\n## 6. groups/\u003cpk\u003e\n\n* This endpoint helps to Update, Delete and Retrieve the Group(Role)\n\n### I. Getting Group by using id\n\n* Getting Group using the Primary Key(id)\n\n```shell\nURL : http://127.0.0.1:8000/groups/\u003cpk(id)\u003e\nRequest Method: GET\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\n```\n\nExample cURL Code:\n\n```shell\ncurl --location 'http://127.0.0.1:8000/groups/\u003cpk(id)\u003e' \\\n--header 'Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ'```\n```\n\n\n### II. Updating Group \n\n* Updating Group using the Primary Key(id)\n\n```shell\nURL : http://127.0.0.1:8000/groups/\u003cpk(id)\u003e\nRequest Method: PUT\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\npayload:\n  {\n    \"name\": \"\u003cName of Group\u003e\",\n    \"permissions\": [\u003cPermission Ids\u003e]\n}\n```\n\nExample cURL code:\n\n```shell\ncurl --location --request PUT 'http://127.0.0.1:8000/groups/\u003cpk(id)\u003e' \\\n--header 'Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ' \\\n--header 'Content-Type: application/json' \\\n--data '{\n    \"name\": \"\u003cName of Group\u003e\",\n    \"permissions\": [\u003cPermission Ids\u003e]\n}'\n```\n\n### III. Deleting Group\n\n* Deleting Group using Primary Key(id)\n\n```shell\nURL : http://127.0.0.1:8000/groups/\u003cpk(id)\u003e\nRequest Method: DELETE\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\n```\n\nExample cURL code:\n\n```shell\ncurl --location --request DELETE 'http://127.0.0.1:8000/groups/\u003cpk(id)\u003e' \\\n--header 'Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ' \\\n--header 'Content-Type: application/json'\n```\n\n\n\n## 7. user_list\n\n* This Endpoint helps to get the list of users\n\n```shell\nURL : http://127.0.0.1:8000/user_list/\nRequest Method: GET\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\n```\nExample cURL Code:\n```shell\ncurl --location 'http://127.0.0.1:8000/user_list/' \\\n--header 'Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ'\n```\n\n\n## 8. user_create\n\n* This Endpoint helps to create the user\n\n```shell\nURL : http://127.0.0.1:8000/user_create/\nRequest Method: POST\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\npayload:\n  {\n    \"password\": \"\u003cpassword\u003e\",\n    \"username\": \"\u003cusername\u003e\",\n    \"first_name\": \"\u003cFirst Name\u003e\",\n    \"last_name\": \"\u003cLast Name\u003e\",\n    \"email\": \"\u003cEmail ID\u003e\",\n    \"groups\": [\u003cAssigning roles(group ids)\u003e],\n    \"user_permissions\": [\u003cAssigning permissions(permission id)\u003e]\n  }\n```\n\nExample cURL Code:\n```shell\ncurl --location 'http://127.0.0.1:8000/user_create/' \\\n--header 'Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n    \"password\": \"\u003cpassword\u003e\",\n    \"username\": \"\u003cusername\u003e\",\n    \"first_name\": \"\u003cFirst Name\u003e\",\n    \"last_name\": \"\u003cLast Name\u003e\",\n    \"email\": \"\u003cEmail ID\u003e\",\n    \"groups\": [\u003cAssigning roles(group ids)\u003e],\n    \"user_permissions\": [\u003cAssigning permissions(permission id)\u003e]\n}'\n```\n\n## 9. users/\u003cusername\u003e\n\n* This Endpoint helps to Update and Delete\n\n### I. Update User\n\n* Updating User\n\n* Here need to pass the data what are the fields to update \n\n```shell\nURL : http://127.0.0.1:8000/users/\u003cusername\u003e\nRequest Method: PUT\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\npayload:\n  {\n    \"password\": \"\u003cPassword\u003e\",\n    \"first_name\": \"\u003cFirst Name\u003e\",\n    \"last_name\": \"\u003cLast Name\u003e\",\n    \"email\": \"\u003cEmail\u003e\",\n    \"groups\": [\u003cAssigning roles(group ids)\u003e],\n    \"user_permissions\": [\u003cAssigning permissions(permission id)\u003e]\n  }\n```\n\nExample cURL Code:\n\n```shell\ncurl --location --request PUT 'http://127.0.0.1:8000/users/\u003cusername\u003e' \\\n--header 'Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ' \\\n--header 'Content-Type: application/json' \\\n--data-raw '{\n    \"password\": \"\u003cPassword\u003e\",\n    \"first_name\": \"\u003cFirst Name\u003e\",\n    \"last_name\": \"\u003cLast Name\u003e\",\n    \"email\": \"\u003cEmail\u003e\",\n    \"groups\": [\u003cAssigning roles(group ids)\u003e],\n    \"user_permissions\": [\u003cAssigning permissions(permission id)\u003e]\n}'\n```\n\n### 2. Delete User\n\n* Deleting User\n\n```shell\nURL : http://127.0.0.1:8000/users/\u003cusername\u003e\nRequest Method: DELETE\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\n```\n\nExample cURL Code:\n\n```shell\ncurl --location --request DELETE 'http://127.0.0.1:8000/users/\u003cusername\u003e' \\\n--header 'Authorization: Bearer 1FxEHf647kC0fxawTzgz3htBKftM4B' \\\n--header 'Content-Type: application/json'\n```\n\n## 10. check_permission\n\n* This Endpoint helps to check the user has the permission or not by using access_token.\n\n```shell\nURL : http://127.0.0.1:8000/check_permission/\nRequest Method: POST\nHeaders:\n  Authorization: Bearer UuOSEQSPz53uE04SMdzbS4VGPXDxjZ\npayload:\n   {\n    \"permission\": \"\u003cPermission codename\u003e\"\n  }\n```\n\nExample cURL Code:\n\n```shell\ncurl --location 'http://localhost:8000/check_permission/' \\\n--header 'Authorization: Bearer ZH0SGfRGdfZQAQNs6RmqpW9GvJlZcB' \\\n--header 'Content-Type: application/json' \\\n--data '{\n    \"permission\": \"add_task\"\n}'\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshanathvemula%2Ftest_oauth2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshanathvemula%2Ftest_oauth2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshanathvemula%2Ftest_oauth2/lists"}