Skip to content

Commit

Permalink
Fix backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
rosmo committed Dec 30, 2024
1 parent afac751 commit 3033275
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/react-spa-app/backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import functions_framework
import os
import requests
import sys
from google.auth.transport import requests
from google.oauth2 import id_token
from flask import abort
Expand Down Expand Up @@ -45,13 +45,14 @@ def validate_iap_jwt(iap_jwt, expected_audience):
)
return (decoded_jwt["sub"], decoded_jwt["email"], "")
except Exception as e:
print(f"**ERROR: JWT validation error {e}**", file=sys.stderr)
return (None, None, f"**ERROR: JWT validation error {e}**")

@functions_framework.http
def hello_function(request):
if os.getenv("IAP_AUDIENCE"):
ret = validate_iap_jwt(request.headers.get("x-goog-iap-jwt-assertion"), os.getenv("IAP_AUDIENCE"))
if ret[0] == None:
if not ret[0]:
abort(403)
return "Hello World: %s" % (ret[0])
return 'Hello World'

0 comments on commit 3033275

Please sign in to comment.