Skip to content

Commit

Permalink
Merge pull request #103 from yjinjo/master
Browse files Browse the repository at this point in the history
Add unauthorized case if credentials don't exist
  • Loading branch information
yjinjo authored Jul 29, 2024
2 parents 3167ab6 + 16bcbc5 commit 3ac8896
Showing 1 changed file with 10 additions and 3 deletions.
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

0 comments on commit 3ac8896

Please sign in to comment.