{ "info": { "author": "Muhammad Usama Bin Liaqat", "author_email": "usama@digidiv.pk", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 2.2", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content" ], "description": ".. image:: https://img.shields.io/badge/version-v1.0.1-blue.svg\n :target: https://pypi.org/project/django-google-api/\n :alt: PyPI Version\n\n.. image:: https://img.shields.io/badge/license-GPL-blue\n :alt: GPL License\n\n.. image:: https://img.shields.io/badge/python-3.5%20%7C%203.6%20%7C%203.7-blue\n :alt: Platform & Version Support\n\nInstallation\n============\n\nInstalling from PyPI is as easy as doing:\n\n.. code-block:: bash\n\n pip install django-google-api\n\n\nIntigration\n===========\n\ndjango-google-api is a library to use Google API with Django\n\nstep:- 1\n--------\n\ncreate **credentials.json** file on DJango project Base Directory where your **manage.py** file exist\n\n | django-project\n | \u251c\u2500\u2500 django-project\n | \u2502 \u251c\u2500\u2500 __init__.py\n | \u2502 \u251c\u2500\u2500 settings.py\n | \u2502 \u251c\u2500\u2500 urls.py\n | \u2502 \u2514\u2500\u2500 wsgi.py\n | \u251c\u2500\u2500 **credentials.json**\n | \u251c\u2500\u2500 manage.py\n | \u2514\u2500\u2500 requirements.txt\n\n\nstep:- 2\n--------\n\nAdd the application to ``INSTALLED_APPS`` setting, for default ORM:\n\n.. code-block:: python\n\n INSTALLED_APPS = [\n ...\n 'django_google.apps.DjangoGoogleConfig',\n ]\n\nstep:- 3\n--------\n\nGoogle OAuth credentials set ``GOOGLE_CLIENT_SECRET_FILE`` and ``GOOGLE_AUTH_SCOPES`` in **setting.py** you can add scope of your choices\n\n.. code-block:: python\n\n GOOGLE_CLIENT_SECRET_FILE = os.path.join(BASE_DIR, 'credentials.json')\n GOOGLE_AUTH_SCOPES = [\n 'https://www.googleapis.com/auth/userinfo.email',\n 'https://www.googleapis.com/auth/userinfo.profile',\n ]\n\nif you're using javascript authentication then add this line to your project also\n\n.. code-block:: python\n\n GOOGLE_CLIENT_ID = \"xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com\"\n\n\n\nUsage:\n======\n\n**execute commands**\n\n.. code-block:: bash\n\n python manage.py makemigrations\n python manage.py migrate\n\nCreate Views in **views.py**\n\n.. code-block:: python\n\n from django.shortcuts import reverse, redirect, render\n from django_google.flow import DjangoFlow,CLIENT_SECRET_FILE, SCOPES\n from django.http.response import JsonResponse\n from django.contrib.auth import get_user_model\n from django.conf import settings\n from django_google.models import GoogleAuth\n User = get_user_model()\n\n flow = DjangoFlow.from_client_secrets_file(client_secrets_file=CLIENT_SECRET_FILE, scopes=SCOPES)\n\n # Auto Redirect to Google Authentication URL (Using Without Javascript)\n def oAuthView(request):\n callback_url=reverse(\"oauth2callback\") # callback Url (oAuth2CallBackView URL)\n return redirect(flow.get_auth_url(request, callback_url=callback_url))\n\n # Google Authentication Call Back VIEW (Using Without Javascript)\n def oAuth2CallBackView(request):\n success_url = \"/dashboard/\" # redirection URL on Success reverse() can b use here\n creds = flow.get_credentails_from_response_url(response_url=request.build_absolute_uri())\n userinfo = flow.get_userinfo(creds=creds)\n try:\n user = User.objects.get(email=userinfo['email'])\n except User.DoesNotExist:\n user = User.objects.create(email=userinfo['email'],\n username=userinfo['email'],\n first_name=userinfo['given_name'],\n last_name=userinfo['family_name']\n )\n finally:\n try:\n gauth = GoogleAuth.objects.get(user=user)\n except GoogleAuth.DoesNotExist:\n gauth = GoogleAuth.objects.create(user=user, creds=creds)\n\n # Return Response as you want or Redirect to some URL\n\n def oAuthJavascriptView(request):\n if request.is_ajax():\n if request.method == \"POST\":\n code = request.POST.get('code')\n flow = DjangoFlow.from_client_secrets_file(client_secrets_file=CLIENT_SECRET_FILE, scopes=SCOPES)\n creds = flow.get_credentials_from_code(code=code, javascript_callback_url=\"https://example.org\")\n userinfo = flow.get_userinfo(creds=creds)\n try:\n user = User.objects.get(email=userinfo['email'])\n except User.DoesNotExist:\n user = User.objects.create(email=userinfo['email'],\n username=userinfo['email'],\n first_name=userinfo['given_name'],\n last_name=userinfo['family_name']\n )\n finally:\n try:\n gauth = GoogleAuth.objects.get(user=user)\n except GoogleAuth.DoesNotExist:\n gauth = GoogleAuth.objects.create(user=user, creds=creds)\n # return JSON Response with Status Code of 200 for success and 400 for errors\n return JsonResponse({}, status=200)\n\n else:\n context = {\n \"client_id\": getattr(settings, 'GOOGLE_CLIENT_ID', None),\n \"scopes\": \" \".join(SCOPES)\n }\n # Render HTML page that havs Google Authentication Page with Javasccript\n return render(request, 'login.html', context)\n\nCreate Views in **urls.py**\n\n.. code-block:: python\n\n from django.urls import path\n from .views import oAuthView, oAuth2CallBackView, oAuthJavascriptView\n\n urlpatterns = [\n path('', oAuthJavascriptView, name=\"login\"),\n path('auth/', oAuthView, name=\"auth\"),\n path('oauth2callback/', oAuth2CallBackView, name=\"oauth2callback\"),\n ]\n\n**login.html** file create Button of your own choice for google auth\n\n.. code-block:: html\n\n \n \n \n \n ", "description_content_type": "text/x-rst", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/digidiv-pk/django-google-api/src", "keywords": "", "license": "GPL License", "maintainer": "", "maintainer_email": "", "name": "django-google-api", "package_url": "https://pypi.org/project/django-google-api/", "platform": "", "project_url": "https://pypi.org/project/django-google-api/", "project_urls": { "Homepage": "https://bitbucket.org/digidiv-pk/django-google-api/src" }, "release_url": "https://pypi.org/project/django-google-api/1.0.1/", "requires_dist": null, "requires_python": "", "summary": "a simple app to create workflow and save credentials fro Django", "version": "1.0.1" }, "last_serial": 5711179, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "2bac7b1c793dd8212c9bcadad95bc979", "sha256": "7f4b999ee8a192f680652e38ddfe3f97e696066e44e1cdadc49e503b5fdf7266" }, "downloads": -1, "filename": "django-google-api-1.0.1.tar.gz", "has_sig": false, "md5_digest": "2bac7b1c793dd8212c9bcadad95bc979", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9222, "upload_time": "2019-08-21T18:46:32", "url": "https://files.pythonhosted.org/packages/4f/d7/f1d05b57b74dad22eeab5d32b036c3f0d2ac7647946171564bf8b7363e55/django-google-api-1.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2bac7b1c793dd8212c9bcadad95bc979", "sha256": "7f4b999ee8a192f680652e38ddfe3f97e696066e44e1cdadc49e503b5fdf7266" }, "downloads": -1, "filename": "django-google-api-1.0.1.tar.gz", "has_sig": false, "md5_digest": "2bac7b1c793dd8212c9bcadad95bc979", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9222, "upload_time": "2019-08-21T18:46:32", "url": "https://files.pythonhosted.org/packages/4f/d7/f1d05b57b74dad22eeab5d32b036c3f0d2ac7647946171564bf8b7363e55/django-google-api-1.0.1.tar.gz" } ] }