Skip to content

Commit ad23739

Browse files
committed
feat: add edge case when refresh_token is None
Signed-off-by: Youngjin Jo <[email protected]>
1 parent ee58859 commit ad23739

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/cloudforet/console_api_v2/service/auth_service.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ def saml(self, params: dict) -> RedirectResponse:
6464
request, console_api_v2_endpoint, dict(form_data)
6565
)
6666
domain_name = self._get_domain_name(domain_id)
67-
refresh_token = self._issue_token(credentials, domain_id)
67+
68+
refresh_token = "unauthorized"
69+
try:
70+
refresh_token = self._issue_token(credentials, domain_id)
71+
except Exception as e:
72+
_LOGGER.error(f"[saml] failed to issue token: {e}")
73+
6874
return self._redirect_response(domain_name, refresh_token)
6975

7076
def saml_sp_metadata(self, domain_id: str) -> Response:
@@ -163,19 +169,14 @@ def _get_domain_name(domain_id: str) -> str:
163169
return response.get("name")
164170

165171
@staticmethod
166-
def _redirect_response(
167-
domain_name: str, refresh_token: str = None
168-
) -> RedirectResponse:
172+
def _redirect_response(domain_name: str, refresh_token: str) -> RedirectResponse:
169173
console_domain: str = config.get_global("CONSOLE_DOMAIN").format(
170174
domain_name=domain_name
171175
)
172176

173-
if refresh_token:
174-
return RedirectResponse(
175-
f"{console_domain}/saml?refresh_token={refresh_token}", status_code=302
176-
)
177-
else:
178-
return RedirectResponse(f"{console_domain}/error-page/401", status_code=302)
177+
return RedirectResponse(
178+
f"{console_domain}/saml?refresh_token={refresh_token}", status_code=302
179+
)
179180

180181
@staticmethod
181182
def _get_acs_url(domain_name: str, domain_id: str) -> str:

0 commit comments

Comments
 (0)