You can find the solution here
I add the key file content as env var to cloud function and followed instructions in the answer below
Google OAuth using domain wide delegation and service account