Skip to content

Commit

Permalink
Merge pull request #86 from SunbirdAI/google_auth
Browse files Browse the repository at this point in the history
url correction
  • Loading branch information
yigagilbert authored Nov 1, 2024
2 parents b18fa31 + 4a04d4e commit d12c684
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from app.routers.frontend import router as frontend_router
from app.routers.tasks import router as tasks_router
from app.utils.exception_utils import validation_exception_handler
from starlette.middleware.sessions import SessionMiddleware


load_dotenv()
logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -86,6 +88,8 @@ async def lifespan(app: FastAPI):
lifespan=lifespan,
)

# Add SessionMiddleware to enable session-based authentication
app.add_middleware(SessionMiddleware, secret_key=os.getenv("SECRET_KEY"))

static_files_directory = Path(__file__).parent.absolute() / "static"
app.mount("/static", StaticFiles(directory=static_files_directory), name="static")
Expand Down
7 changes: 2 additions & 5 deletions app/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,12 @@ async def change_password(

return {"message": "Password change successful", "success": True}

@router.get("/auth/google/login", name="auth/google_login")
@router.get("/google/login", name="auth/google_login")
async def google_login(request: Request):
redirect_uri = request.url_for("google_callback")
return await oauth.google.authorize_redirect(request, redirect_uri)


@router.get("/auth/google/callback")
@router.get("/google/callback", name="google_callback")
async def google_callback(request: Request, db: AsyncSession = Depends(get_db)):
token = await oauth.google.authorize_access_token(request)
user_info = await oauth.google.parse_id_token(request, token)
Expand Down Expand Up @@ -212,5 +211,3 @@ async def save_organization(

# Redirect to account or another relevant page
return RedirectResponse(url="/account", status_code=status.HTTP_303_SEE_OTHER)


0 comments on commit d12c684

Please sign in to comment.