How to create Google Cloud JWT Token Function using Python
Hello Guys. Today we will try to understand how to create Google Cloud Function using Python.
Steps are as follows.
Step 1:
Login to your Google Cloud Account
Step 2:
After login you can see a search box on top. Type Cloud Function. Now Click on “Cloud Functions” Option
Step 3:
Once Click on it will open Cloud Functions Dashboard. Click on “CREATE FUNCTION” Option.
Step 4:
You will get below screen. Enter your Function name. If required change the region and click on “save” Button. Below you will get “Next” Button. Click on it.
Now you can see 2 Files.
A. main.py
B. requirement.txt
Add below code in “main.py” & Click on “DEPLOY” Button.
import jwt
import jsondef generateToken(request):
key = “JWT_AUTH_KEY”
encoded_jwt = jwt.encode({“shardul”: “hello”}, key, algorithm=”HS256")
dataJWTJson = json.dumps({‘token’:encoded_jwt})
return dataJWTJson
Once Run the Cloud Function your out put will be as follows.