Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unauthorized case if credentials don't exist #103

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/cloudforet/console_api_v2/service/auth_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
from typing import Union

from fastapi import Request, Response
from fastapi.responses import RedirectResponse
Expand Down Expand Up @@ -62,9 +63,13 @@ def saml(self, params: dict) -> RedirectResponse:
credentials = self._extract_credentials(
request, console_api_v2_endpoint, dict(form_data)
)
refresh_token = self._issue_token(credentials, domain_id)

domain_name = self._get_domain_name(domain_id)
return self._redirect_response(domain_name, refresh_token)
if credentials:
refresh_token = self._issue_token(credentials, domain_id)
return self._redirect_response(domain_name, refresh_token)
else:
return self._redirect_response(domain_name, None)

def saml_sp_metadata(self, domain_id: str) -> Response:
sp_entity_id = domain_id
Expand Down Expand Up @@ -162,7 +167,9 @@ def _get_domain_name(domain_id: str) -> str:
return response.get("name")

@staticmethod
def _redirect_response(domain_name: str, refresh_token: str) -> RedirectResponse:
def _redirect_response(
domain_name: str, refresh_token: Union[str, None]
) -> RedirectResponse:
console_domain: str = config.get_global("CONSOLE_DOMAIN").format(
domain_name=domain_name
)
Expand Down
Loading