Skip to content

Commit

Permalink
Merge pull request #71 from ImMin5/feature-support-mfa-authentication
Browse files Browse the repository at this point in the history
Extract external user_id
  • Loading branch information
ImMin5 authored Nov 9, 2023
2 parents 961a257 + 56fdf48 commit 21646aa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def authenticate(self, user_id, domain_id, credentials):

endpoint = self.domain_mgr.get_auth_plugin_endpoint_by_vo(self.domain)
auth_user_info = self._authenticate_with_plugin(endpoint, credentials)
credentials['user_id'] = auth_user_info.get('user_id')

_LOGGER.info(f'[authenticate] Authentication success. (user_id={auth_user_info.get("user_id")})')

Expand Down
5 changes: 4 additions & 1 deletion src/spaceone/identity/service/token_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ def issue(self, params):
token_manager = self._get_token_manager(user_id, user_type, domain_id)
token_manager.authenticate(user_id, domain_id, params['credentials'])

if user_type == 'EXTERNAL':
user_id = params['credentials'].get('user_id')

user_vo = self.user_mgr.get_user(user_id, domain_id)
user_mfa = user_vo.mfa if user_vo.mfa else {}
user_mfa = user_vo.mfa.to_dict() if user_vo.mfa else {}

if user_mfa.get('state', 'DISABLED') == 'ENABLED':
if verify_code:
Expand Down
6 changes: 3 additions & 3 deletions src/spaceone/identity/service/user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def enable_mfa(self, params):
token_manager: LocalTokenManager = self.locator.get_manager('LocalTokenManager')

user_vo = self.user_mgr.get_user(user_id, domain_id)
user_mfa = user_vo.mfa.to_dict()
user_mfa = user_vo.mfa.to_dict() if user_vo.mfa else {}

if user_mfa.get('state', 'DISABLED') == 'ENABLED':
raise ERROR_MFA_ALREADY_ENABLED(user_id=user_id)
Expand Down Expand Up @@ -358,7 +358,7 @@ def disable_mfa(self, params):
force = params.get('force', False)

user_vo = self.user_mgr.get_user(user_id, domain_id)
user_mfa = user_vo.mfa.to_dict()
user_mfa = user_vo.mfa.to_dict() if user_vo.mfa else {}

if user_mfa.get('state', 'DISABLED') == 'DISABLED':
raise ERROR_MFA_ALREADY_DISABLED(user_id=user_id)
Expand Down Expand Up @@ -394,7 +394,7 @@ def confirm_mfa(self, params):
token_manager: LocalTokenManager = self.locator.get_manager('LocalTokenManager')

if token_manager.check_mfa_verify_code(user_id, domain_id, verify_code):
user_mfa = user_vo.mfa.to_dict()
user_mfa = user_vo.mfa.to_dict() if user_vo.mfa else {}
if user_mfa.get('state', 'DISABLED') == 'ENABLED':
user_mfa = {'state': 'DISABLED'}
elif user_mfa.get('state', 'DISABLED') == 'DISABLED':
Expand Down

0 comments on commit 21646aa

Please sign in to comment.