Skip to content

Commit

Permalink
chore: prepares oauth-scheme for dependency injetion in FastAPI with …
Browse files Browse the repository at this point in the history
…corrected callback
  • Loading branch information
arnoldknott committed Dec 9, 2024
1 parent c164536 commit 218a16d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backendAPI/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN pip install --upgrade pip && \
# --no-create-home \
# backend-user
# USER backend-user
CMD ["uvicorn", "main:app", "--reload", "--host", "0.0.0.0", "--port", "80"]
CMD ["uvicorn", "main:app", "--reload", "--log-level", "'warning'" ,"--host", "0.0.0.0", "--port", "80"]

FROM base AS prod
LABEL org.opencontainers.image.source https://github.com/arnoldknott/fullstacksandbox23
Expand Down
5 changes: 3 additions & 2 deletions backendAPI/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,20 @@ async def lifespan(app: FastAPI):
# scopes={
# f"api://{config.API_SCOPE}/api.read": "Read API",
# f"api://{config.API_SCOPE}/api.write": "Write API",
# f"api://{config.API_SCOPE}/socketio": "Socket.io",
# },
# scheme_name="OAuth2 Authorization Code",
# description="OAuth2 Authorization Code Bearer implementation for Swagger UI - identity provider is Microsoft Azure AD",
# )

# swagger_ui_parameters = {
# "oauth2RedirectUrl": "http://localhost:8000/oauth/callback", # replace with your actual callback URL
# "oauth2RedirectUrl": "http://localhost:8000/docs/oauth2-redirect", # replace with your actual callback URL
# }

# or:
# swagger_ui_parameters = {
# "network": {
# "oauth2RedirectUrl": "http://localhost:8000/oauth/callback", # replace with your actual callback URL
# "oauth2RedirectUrl": "http://localhost:8000/docs/oauth2-redirect", # replace with your actual callback URL
# }
# }

Expand Down
4 changes: 2 additions & 2 deletions backendAPI/src/routers/api/v1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# "code": code,
# "client_id": config.AZURE_CLIENT_ID,
# "client_secret": config.BACK_CLIENT_SECRET,
# "redirect_uri": "http://localhost:8000/callback", # replace with your actual callback URL
# "redirect_uri": "http://localhost:8000/docs/oauth2-redirect", # replace with your actual callback URL
# }
# response = httpx.post(
# "https://login.microsoftonline.com/{config.AZURE_TENANT_ID}/oauth2/token",
Expand Down Expand Up @@ -106,7 +106,7 @@ async def get_keyvault():
# }

# # Not working yet, callback needs to handle the token
# @router.get("/callback")
# @router.get("/docs/oauth2-redirect")
# def callback(code: str = Depends(oauth2_scheme)):
# token = exchange_code_for_token(code)
# if not token:
Expand Down
4 changes: 2 additions & 2 deletions backendAPI/src/routers/socketio/v1/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ async def on_connect(
)
except Exception as err:
logger.error(f"Client with session id {sid} failed to authenticate.")
print("=== base - on_connect - Exception ===")
print(err, flush=True)
# print("=== base - on_connect - Exception ===")
# print(err, flush=True)
raise ConnectionRefusedError("Authorization failed")
else:
current_user = None
Expand Down

0 comments on commit 218a16d

Please sign in to comment.