How to implement more than one endpoint in a Google Cloud Function?

508 Views Asked by At

My intention is to use a unique Google Cloud Function to accommodate a few endpoints.

I do have a super simple code using the Python functions-framework to take an Id Token and validate whether it is valid. I'd like to add one more endpoint to revoke that Id Token. I haven't found any samples around the web. Since the decorators are not so suggestive how to create more endpoints to the same Google Cloud Function (if it is possible)?

import functions_framework
import firebase_admin
from firebase_admin import auth

from flask import abort

# Initialize the app
cred = credentials.Certificate('../credentials-dev.json')
firebase_admin.initialize_app(cred)

# Register an HTTP function with the Functions Framework
@functions_framework.http
def insert_monthly(request):
  # Validate auth
  print(request.headers)
  user_uid = validate_auth(request)

  # Return an HTTP response
  return user_uid


def validate_auth(request):
    try:
        id_token = request.headers.get('Authorization').split(' ')[1]
        decoded_token = auth.verify_id_token(id_token, check_revoked=True)
        uid = decoded_token['uid']
        return uid
    except Exception as e:
        abort(400, description=str(e))
0

There are 0 best solutions below