File size: 1,496 Bytes
e2bcf9c
 
 
27c332b
 
 
240ebb2
e2bcf9c
 
 
 
 
 
 
 
 
55da466
d8fb293
8088ccf
8de4a33
 
 
c8a187f
8de4a33
 
 
 
 
 
 
 
 
 
d8fb293
55da466
8de4a33
 
22eb9af
ef3219c
9b59406
 
 
 
 
 
 
e2bcf9c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from fastapi import FastAPI , Request, APIRouter, Depends, HTTPException
from starlette.middleware.cors import CORSMiddleware
from routers import receipt_radar_callback_router
import os
from dotenv import load_dotenv
load_dotenv()
import requests
app = FastAPI()
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["DELETE", "GET", "POST", "PUT"],
    allow_headers=["*"],
)
app = FastAPI()
@app.post("/test")
async def test(request:Request):
    print("inside test")
    body = await request.json()
    token_url = "https://oauth2.googleapis.com/token"
    data= {
        "refresh_token":body.get('refresh_token',None),
        "client_id": os.getenv("GOOGLE_CLIENT_ID"),
        "client_secret": os.getenv("GOOGLE_CLIENT_SECRET"),
        "redirect_uri": os.getenv("GOOGLE_REDIRECT_URI"),
        "grant_type": "refresh_token",
        "access_type": "offline"
    }
    
    response = requests.post(token_url, data=data)
    print(response.json())
    access_token = response.json().get("access_token",None)
    body = await request.json()
    print(body.get('refresh_token',None))
    print("URL endpoint hit getting access_token!!")
    return {"access_token":access_token}


@app.post("/test2")
async def test2(request:Request):
    body = await request.json()
    print(body.get('access_token',None))
    print("Url endpoint test 2 hit !!")
    return {"status":"True"}

app.include_router(receipt_radar_callback_router.router)