Skip to content

Commit

Permalink
Support google jwt auth
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanarijit committed Jun 25, 2024
1 parent 4bef28a commit 34f0b71
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions apphelpers/socialauth/goog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

from google.auth.transport import requests
from google.oauth2 import id_token
from requests_oauthlib import OAuth2Session

try:
Expand All @@ -11,7 +13,15 @@
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "True"


def fetch_info(access_token):
session = OAuth2Session(token={"access_token": access_token})
userinfo = session.get("https://www.googleapis.com/oauth2/v1/userinfo").json()
def fetch_info(access_token, jwt=False):
if jwt:
request = requests.Request()
userinfo = id_token.verify_oauth2_token(
id_token=access_token, request=request, audience=settings.G_CLIENT_ID
)
else:
session = OAuth2Session(
token={"access_token": access_token}, client_id=settings.G_CLIENT_ID
)
userinfo = session.get("https://www.googleapis.com/oauth2/v1/userinfo").json()
return userinfo
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
with open("CHANGELOG.rst") as history_file:
history = history_file.read()

requirements = ["loguru"]
requirements = ["loguru", "google-auth"]

setup_requirements = []

Expand Down

0 comments on commit 34f0b71

Please sign in to comment.