Omkar008 commited on
Commit
8de4a33
1 Parent(s): 5f031ae

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -2
main.py CHANGED
@@ -13,10 +13,24 @@ app.add_middleware(
13
  app = FastAPI()
14
  @app.post("/test")
15
  async def test(request:Request):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  body = await request.json()
17
  print(body.get('refresh_token',None))
18
- print("URL endpoint hit !!")
19
- return {"access_token":"abcd"}
20
 
21
  @app.post("/test2")
22
  async def test2(request:Request):
 
13
  app = FastAPI()
14
  @app.post("/test")
15
  async def test(request:Request):
16
+ body = await request.json()
17
+ token_url = "https://oauth2.googleapis.com/token"
18
+ data= {
19
+ "code":body.get('refresh_token',None),
20
+ "client_id": os.getenv("GOOGLE_CLIENT_ID"),
21
+ "client_secret": os.getenv("GOOGLE_CLIENT_SECRET"),
22
+ "redirect_uri": os.getenv("GOOGLE_REDIRECT_URI"),
23
+ "grant_type": "refresh_token",
24
+ "access_type": "offline"
25
+ }
26
+
27
+ response = requests.post(token_url, data=data)
28
+ print(response.json())
29
+ access_token = response.json().get("access_token",None)
30
  body = await request.json()
31
  print(body.get('refresh_token',None))
32
+ print("URL endpoint hit getting access_token!!")
33
+ return {"access_token":access_token}
34
 
35
  @app.post("/test2")
36
  async def test2(request:Request):