Google APIs OAuth Django
A library to help integrate Google OAuth 2.0 to your Django application. This library retrieves the necessary tokens you need to access the Google APIs your application is configured for.
Installation
pip install google-apis-oauth-django
Usage
Redirecting users to the login screen
from django.shortcuts import HttpResponseRedirect
import google_apis_oauth
def RedirectToOAuthPage(request):
oauth_url = google_apis_oauth.get_authorization_url(
# Path of the "client_id.json" file
JSON_FILEPATH,
# Authorization scopes required
SCOPES,
# The url where the google oauth should redirect
# after a successful login.
REDIRECT_URI,
# Force the consent prompt even if the user was authorized
# previously. Defaults to False.
True)
return HttpResponseRedirect(url)
Retreving and storing the credentials after successful login
import google_apis_oauth
def RedirectView(request):
try:
# Get user credentials
credentials = google_apis_oauth.get_crendentials_from_callback(
request,
JSON_FILEPATH,
SCOPES,
REDIRECT_URI
)
# Stringify credentials for storing them in the DB
stringified_token = google_apis_oauth.stringify_credentials(
credentials)
# Store the credentials safely in the DB
...
# Now that you have stored the user credentials you
# can redirect user to your main application.
...
except google_apis_oauth.exceptions.InvalidLoginException:
# Handle unauthenticated request to the callback uri.
Loading and using the user credentials
import google_apis_oauth
from googleapiclient.discovery import build
# Use the stringified token to get a credentials object
# that can be used to authenticate requests made by
# google-api-python-client
# refreshed is a boolean that tells if the token was expired and was renewed.
# You may want to update the credentials in the database if it is True.
creds, refreshed = google_apis_oauth.load_credentials(stringified_token)
# Using credentials in google-api-python-client.
service = build('calendar', 'v3', credentials=creds)
...
Example
You can refer to this blog for an example where this library is used.
Metadata
Release files for google-apis-oauth-django 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| google-apis-oauth-django-1.0.0.tar.gz | 4.1 kB | Without provenance | Details for google-apis-oauth-django-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| google_apis_oauth_django-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for google_apis_oauth_django-1.0.0-py3-none-any.whl |
Total release size: 9.0 kB
Release files / google-apis-oauth-django-1.0.0.tar.gz
| Download URL | google-apis-oauth-django-1.0.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf1e2493d7edf2977eeec8b82001c3e383a0fa88a2254737f0d671b1e46a4c95
|
|
BLAKE2b-256 checksum How to use checksums |
4678ae5eed232037b37615abd034285367abcc052b5cc26876d546f63b4533a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.5
|
Release files / google_apis_oauth_django-1.0.0-py3-none-any.whl
| Download URL | google_apis_oauth_django-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8350e74124d98970e9d0937ce0f25d49ecc4e6ee74ed1169311219ec73a3b2cf
|
|
BLAKE2b-256 checksum How to use checksums |
c11d5241c9d5603c8bb7e97c60b64d5f85967d1dd03d56df837afe9378b3d79e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.5
|
Security for google-apis-oauth-django 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.