@@ -82,6 +82,38 @@ def update(self, params: UserProfileUpdateRequest) -> Union[UserResponse, dict]:
8282
8383 return UserResponse (** user_vo .to_dict ())
8484
85+ @transaction (permission = "identity:UserProfile.write" , role_types = ["USER" ])
86+ @convert_model
87+ def set_refresh_timeout (
88+ self , params : UserProfileSetRefreshTokenTimeout
89+ ) -> Union [UserResponse , dict ]:
90+ """
91+ Args:
92+ params (UserProfileSetRefreshTokenTimeout): {
93+ "refresh_timeout": "int",
94+ "user_id": "str", # inject from auth
95+ "domain_id": "str" # inject from auth
96+ }
97+ Returns:
98+ UserResponse:
99+ """
100+
101+ user_id = params .user_id
102+ domain_id = params .domain_id
103+ user_vo = self .user_mgr .get_user (user_id , domain_id )
104+
105+ if user_vo .role_type != "DOMAIN_ADMIN" :
106+ raise ERROR_PERMISSION_DENIED ()
107+
108+ refresh_timeout = self ._get_refresh_timeout_from_config (params .refresh_timeout )
109+ print (refresh_timeout )
110+ user_vo = self .user_mgr .update_user_by_vo (
111+ {"refresh_timeout" : refresh_timeout }, user_vo
112+ )
113+
114+ print (user_vo .refresh_timeout )
115+ return UserResponse (** user_vo .to_dict ())
116+
85117 @transaction (permission = "identity:UserProfile.write" , role_types = ["USER" ])
86118 @convert_model
87119 def verify_email (self , params : UserProfileVerifyEmailRequest ) -> None :
@@ -620,3 +652,20 @@ def _get_my_workspace_groups_info(
620652 def _check_mfa_options (options , mfa_type ):
621653 if mfa_type in ["EMAIL" ] and not options :
622654 raise ERROR_REQUIRED_PARAMETER (key = "options.email" )
655+
656+ @staticmethod
657+ def _get_refresh_timeout_from_config (refresh_timeout : int ) -> int :
658+ identity_conf = config .get_global ("IDENTITY" ) or {}
659+ token_conf = identity_conf .get ("token" , {})
660+ config_refresh_timeout = token_conf .get ("refresh_timeout" )
661+ if refresh_timeout < config_refresh_timeout :
662+ raise ERROR_INVALID_PARAMETER (
663+ key = "refresh_timeout" ,
664+ reason = f"Minimum value for refresh_timeout is { config_refresh_timeout } " ,
665+ )
666+ refresh_timeout = max (refresh_timeout , config_refresh_timeout )
667+
668+ config_admin_refresh_timeout = token_conf .get ("admin_refresh_timeout" , 2592000 )
669+ refresh_timeout = min (refresh_timeout , config_admin_refresh_timeout )
670+
671+ return refresh_timeout
0 commit comments