Omkar008 commited on
Commit
e2bcf9c
1 Parent(s): d34428a

adding files

Browse files
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI , Request, APIRouter, Depends, HTTPException
2
+ from starlette.middleware.cors import CORSMiddleware
3
+ from routers import receipt_radar_callback_router
4
+
5
+ app = FastAPI()
6
+
7
+ app.add_middleware(
8
+ CORSMiddleware,
9
+ allow_origins=["*"],
10
+ allow_credentials=True,
11
+ allow_methods=["DELETE", "GET", "POST", "PUT"],
12
+ allow_headers=["*"],
13
+ )
14
+
15
+
16
+ app = FastAPI()
17
+
18
+ app.include_router(receipt_radar_callback_router.router)
constants.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dotenv import load_dotenv
2
+ import os
3
+ load_dotenv()
4
+
5
+ TOKEN_GENERATION_API="https://oauth2.googleapis.com/token"
6
+ USER_INFO_API = "https://www.googleapis.com/oauth2/v1/userinfo"
7
+ REFRESH_TOKEN_PAYLOAD={
8
+
9
+ "client_id": os.getenv("GOOGLE_CLIENT_ID"),
10
+ "client_secret": os.getenv("GOOGLE_CLIENT_SECRET"),
11
+ "redirect_uri": os.getenv("GOOGLE_REDIRECT_URI"),
12
+ "grant_type": "authorization_code",
13
+ "access_type": "offline"
14
+ }
dependencies/database.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from supabase import create_client, Client
2
+ import os
3
+ from dotenv import load_dotenv
4
+ load_dotenv()
5
+
6
+ class SupabaseDb:
7
+ SUPABASE_URL: str = os.getenv("SUPABASE_URL")
8
+ SUPABASE_ANON_KEY: str = os.getenv("SUPABASE_ANON_KEY")
9
+
10
+ def supabase_client(self):
11
+ client = create_client(self.SUPABASE_URL,self.SUPABASE_ANON_KEY)
12
+ return client
13
+
14
+ def get_hushh_id(self,email:str):
15
+ client = self.supabase_client()
16
+ response = client.table("receipt_radar_authenticate").select("*").eq('email',f'{email}').execute()
17
+ print(response)
18
+ return "omkar"
models/supabase_init.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic import BaseModel
2
+ from dotenv import load_dotenv
3
+ from supabase import create_client
4
+ from functools import lru_cache
5
+ import os
6
+
7
+ @lru_cache(maxsize=1)
8
+ class Supabase_Settings(BaseModel):
9
+
10
+ SUPABASE_URL: str = os.getenv("SUPABASE_URL")
11
+ SUPABASE_ANON_KEY: str = os.getenv("SUPABASE_ANON_KEY")
12
+ SUPABASE_SERVICE_KEY: str = os.getenv("SUPABASE_SERVICE_KEY")
13
+
14
+
15
+
16
+ @lru_cache(maxsize=1)
17
+ class Supabase_Clients:
18
+ values = Supabase_Settings()
19
+ anon_supabase = create_client(values.SUPABASE_URL, values.SUPABASE_ANON_KEY)
routers/receipt_radar_callback_router.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter , Request ,HTTPException
2
+ from constants import TOKEN_GENERATION_API,REFRESH_TOKEN_PAYLOAD,USER_INFO_API
3
+ import requests
4
+ from dependencies import database as sp
5
+ import os
6
+ from dotenv import load_dotenv
7
+ load_dotenv()
8
+
9
+ router = APIRouter(prefix="/receipt_radar")
10
+
11
+ @router.get("/callback")
12
+ async def callback(code:str):
13
+ token_url = TOKEN_GENERATION_API
14
+ print("Authorisation code : ",code)
15
+ data= {
16
+ "code":code,
17
+ "client_id": os.getenv("GOOGLE_CLIENT_ID"),
18
+ "client_secret": os.getenv("GOOGLE_CLIENT_SECRET"),
19
+ "redirect_uri": os.getenv("GOOGLE_REDIRECT_URI"),
20
+ "grant_type": "authorization_code",
21
+ "access_type": "offline"
22
+ }
23
+
24
+ response = requests.post(token_url, data=data)
25
+ print(response.json())
26
+ access_token = response.json().get("access_token",None)
27
+ refresh_token=response.json().get('refresh_token',None)
28
+ user_info_api = USER_INFO_API +"?access_token="+f"{access_token}"
29
+ user_info_response = requests.get(user_info_api)
30
+ user_email = user_info_response.json().get('email')
31
+ print(user_email)
32
+ # hushh_id = await sp.SupabaseDb().get_hushh_id(user_email)
33
+
34
+
35
+ return {"payload":response.json()}