How to create Google Cloud JWT Token Function using Python

shardul Kulkarni
2 min readMar 18, 2021

--

Google Cloud Function with Pytho For Generating JWT Token

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 json

def 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.

--

--

shardul Kulkarni
shardul Kulkarni

Written by shardul Kulkarni

I have more than 12.5 years exp in IT Domain. Have good hands on PHP, Python, MySql etc

No responses yet