|
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) |