Skip to content

Add endpoints values at token payload #407

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

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/spaceone/identity/conf/global_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"token_timeout": 1800, # 30 minutes
"token_max_timeout": 604800, # 7 days
"refresh_timeout": 10800, # 3 hours
"admin_refresh_timeout": 2592000, # 30days
"admin_refresh_max_timeout": 2419200, # 28 days
},
"mfa": {"verify_code_timeout": 300},
}
Expand Down Expand Up @@ -139,3 +139,6 @@

# System Token Settings
TOKEN = ""

# IDENTITY BASE URL for TOKEN PAYLOAD
IDENTITY_BASE_URL = ""
10 changes: 10 additions & 0 deletions src/spaceone/identity/lib/key_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def generate_token(
permissions: list = None,
projects: list = None,
injected_params: dict = None,
endpoints: list = None,
identity_base_url: str = None,
) -> str:
payload = {
"iss": "spaceone.identity",
Expand Down Expand Up @@ -74,6 +76,12 @@ def generate_token(
if injected_params:
payload["injected_params"] = injected_params

if endpoints:
payload["endpoints"] = endpoints

if identity_base_url:
payload["identity_base_url"] = identity_base_url

if token_type == "REFRESH_TOKEN":
return JWTUtil.encode(payload, self.refresh_prv_jwk)
else:
Expand All @@ -96,5 +104,7 @@ def _print_key(payload: dict):
f'projects: {payload.get("projects")},'
f'permissions: {payload.get("permissions")},'
f'injected_params: {payload.get("injected_params")},'
f'endpoints: {payload.get("endpoints")},'
f'identity_base_url: {payload.get("identity_base_url")},'
f'ver: {payload.get("ver")} )'
)
10 changes: 10 additions & 0 deletions src/spaceone/identity/manager/token_manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def issue_token(
)

timeout = self.set_timeout(timeout)
endpoints = config.get_global("ENDPOINTS")
identity_base_url = config.get_global("IDENTITY_BASE_URL")

access_token = key_gen.generate_token(
"ACCESS_TOKEN",
Expand All @@ -77,6 +79,8 @@ def issue_token(
workspace_id=workspace_id,
permissions=permissions,
projects=projects,
endpoints=endpoints,
identity_base_url=identity_base_url,
)

refresh_token = key_gen.generate_token(
Expand Down Expand Up @@ -136,6 +140,9 @@ def _get_refresh_token_timeout(self) -> int:
):
refresh_timeout = max(self.user.refresh_timeout, refresh_timeout)

if refresh_timeout > self.CONST_MAX_REFRESH_TIMEOUT:
refresh_timeout = self.CONST_MAX_REFRESH_TIMEOUT

return refresh_timeout

@staticmethod
Expand All @@ -158,4 +165,7 @@ def _load_conf(self):
self.CONST_TOKEN_TIMEOUT = token_conf.get("token_timeout", 1800)
self.CONST_VERIFY_CODE_TIMEOUT = token_conf.get("verify_code_timeout", 3600)
self.CONST_REFRESH_TIMEOUT = token_conf.get("refresh_timeout", 10800)
self.CONST_MAX_REFRESH_TIMEOUT = token_conf.get(
"admin_refresh_max_timeout", 2592000
)
self.CONST_MAX_TOKEN_TIMEOUT = token_conf.get("token_max_timeout", 604800)
6 changes: 4 additions & 2 deletions src/spaceone/identity/service/user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,9 @@ def _get_refresh_timeout_from_config(refresh_timeout: int) -> int:
)
refresh_timeout = max(refresh_timeout, config_refresh_timeout)

config_admin_refresh_timeout = token_conf.get("admin_refresh_timeout", 2592000)
refresh_timeout = min(refresh_timeout, config_admin_refresh_timeout)
config_admin_refresh_max_timeout = token_conf.get(
"admin_refresh_max_timeout", 2419200
)
refresh_timeout = min(refresh_timeout, config_admin_refresh_max_timeout)

return refresh_timeout
Loading