add supertokens api to API hub
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
from supertokens_python import init, InputAppInfo, SupertokensConfig
|
||||||
|
from supertokens_python.recipe import emailpassword, session, dashboard
|
||||||
|
|
||||||
|
init(
|
||||||
|
app_info=InputAppInfo(
|
||||||
|
app_name="MIH_API_HUB",
|
||||||
|
api_domain="http://localhost:8080/",
|
||||||
|
website_domain="http://mzansi-innovation-hub.co.za",
|
||||||
|
api_base_path="/auth",
|
||||||
|
website_base_path="/auth"
|
||||||
|
),
|
||||||
|
supertokens_config=SupertokensConfig(
|
||||||
|
# https://try.supertokens.com is for demo purposes. Replace this with the address of your core instance (sign up on supertokens.com), or self host a core.
|
||||||
|
connection_uri="http://MIH-SuperTokens:3567/",
|
||||||
|
api_key="leatucczyixqwkqqdrhayiwzeofkltds"
|
||||||
|
),
|
||||||
|
framework='fastapi',
|
||||||
|
recipe_list=[
|
||||||
|
session.init(), # initializes session features
|
||||||
|
emailpassword.init(),
|
||||||
|
dashboard.init(admins=[
|
||||||
|
"yasienmeth@gmail.com",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
mode='asgi' # use wsgi if you are running using gunicorn
|
||||||
|
)
|
||||||
@@ -3,6 +3,11 @@ from pydantic import BaseModel
|
|||||||
from .routers import docOffices, patients, patients_files, patients_notes, users, fileStorage, medicine
|
from .routers import docOffices, patients, patients_files, patients_notes, users, fileStorage, medicine
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.middleware import Middleware
|
from fastapi.middleware import Middleware
|
||||||
|
from supertokens_python import get_all_cors_headers
|
||||||
|
from supertokens_python.framework.fastapi import get_middleware
|
||||||
|
from supertokens_python.recipe.session.framework.fastapi import verify_session
|
||||||
|
from supertokens_python.recipe.session import SessionContainer
|
||||||
|
from fastapi import Depends
|
||||||
|
|
||||||
origins = [
|
origins = [
|
||||||
"http://localhost",
|
"http://localhost",
|
||||||
@@ -14,17 +19,25 @@ origins = [
|
|||||||
"*",
|
"*",
|
||||||
]
|
]
|
||||||
|
|
||||||
middleware = [
|
# middleware = [
|
||||||
Middleware(
|
# Middleware(
|
||||||
|
# CORSMiddleware,
|
||||||
|
# allow_origins=origins,
|
||||||
|
# allow_credentials=True,
|
||||||
|
# allow_methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
|
||||||
|
# allow_headers=["Content-Type"] + get_all_cors_headers(),
|
||||||
|
# )
|
||||||
|
# ]
|
||||||
|
|
||||||
|
app = FastAPI()#middleware=middleware)
|
||||||
|
app.add_middleware(get_middleware())
|
||||||
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=origins,
|
allow_origins=origins,
|
||||||
allow_credentials=True,
|
allow_credentials=True,
|
||||||
allow_methods=["*"],
|
allow_methods=["GET", "PUT", "POST", "DELETE", "OPTIONS", "PATCH"],
|
||||||
allow_headers=["*"],
|
allow_headers=["Content-Type"] + get_all_cors_headers()
|
||||||
)
|
)
|
||||||
]
|
|
||||||
|
|
||||||
app = FastAPI(middleware=middleware)
|
|
||||||
app.include_router(docOffices.router)
|
app.include_router(docOffices.router)
|
||||||
app.include_router(patients.router)
|
app.include_router(patients.router)
|
||||||
app.include_router(patients_files.router)
|
app.include_router(patients_files.router)
|
||||||
@@ -39,6 +52,13 @@ app.include_router(medicine.router)
|
|||||||
def read_root():
|
def read_root():
|
||||||
return serverRunning()
|
return serverRunning()
|
||||||
|
|
||||||
|
# Check if server is up
|
||||||
|
@app.get("/session")
|
||||||
|
def read_root():
|
||||||
|
async def like_comment(session: SessionContainer = Depends(verify_session())):
|
||||||
|
user_id = session.get_user_id()
|
||||||
|
|
||||||
|
return {"Session id": user_id}
|
||||||
|
|
||||||
def serverRunning():
|
def serverRunning():
|
||||||
return {"Status": "Server is Up and Running"}
|
return {"Status": "Server is Up and Running"}
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ reportlab
|
|||||||
requests
|
requests
|
||||||
watchfiles==0.21.0
|
watchfiles==0.21.0
|
||||||
python-multipart
|
python-multipart
|
||||||
xlrd
|
xlrd
|
||||||
|
supertokens-python
|
||||||
Reference in New Issue
Block a user