
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
google-apis-oauth-django
Advanced tools
A library to help integrate Google OAuth 2.0 to your Django application.
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.
pip install google-apis-oauth-django
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)
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.
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)
...
You can refer to this blog for an example where this library is used.
FAQs
A library to help integrate Google OAuth 2.0 to your Django application.
We found that google-apis-oauth-django demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.