Skip to content
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

Add idp initiate feature #4

Merged
merged 1 commit into from
Jun 3, 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
16 changes: 13 additions & 3 deletions src/plugin/connector/saml_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def init(self, options: dict) -> dict:
'identity_provider': 'str',
'icon': 'str',
'metadata_url': 'str',
'sp_metadata_url': 'str',

Returns:
'metadata': 'dict'
Expand All @@ -49,12 +50,15 @@ def init(self, options: dict) -> dict:

return metadata

def authorize(self, params: dict, metadata_url: str, domain_id: str) -> dict:
def authorize(
self, params: dict, metadata_url: str, sp_metadata_url: str, domain_id: str
) -> dict:
"""Authorizes the user using SAML.

Args:
'params': 'dict',
'metadata_url': 'str',
'sp_metadata_url': 'str',
'domain_id': 'str',

Returns:
Expand All @@ -63,7 +67,7 @@ def authorize(self, params: dict, metadata_url: str, domain_id: str) -> dict:
Raises:
ERROR_AUTHENTICATE_FAILURE: If authentication fails
"""
self._set_saml_settings(metadata_url, domain_id)
self._set_saml_settings(metadata_url, sp_metadata_url, domain_id)

auth = OneLogin_Saml2_Auth(
params,
Expand Down Expand Up @@ -98,11 +102,17 @@ def _get_user_info_from_auth(auth: OneLogin_Saml2_Auth) -> dict:

return user_info

def _set_saml_settings(self, metadata_url: str, domain_id: str) -> None:
def _set_saml_settings(
self,
metadata_url: str,
sp_metadata_url: str,
domain_id: str,
) -> None:
"""Sets the SAML settings using the metadata URL and domain ID.

Args:
'metadata_url': 'str',
'sp_metadata_url': 'str',
'domain_id': 'str',
"""
xml_data = self._fetch_xml(metadata_url)
Expand Down
3 changes: 1 addition & 2 deletions src/plugin/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from spaceone.identity.plugin.external_auth.lib.server import \
ExternalAuthPluginServer
from spaceone.identity.plugin.external_auth.lib.server import ExternalAuthPluginServer

from plugin.manager.external_auth_manager import ExternalAuthManager

Expand Down
6 changes: 5 additions & 1 deletion src/plugin/manager/external_auth_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def init(self, options: dict) -> dict:
'identity_provider': 'str',
'icon': 'str',
'metadata_url': 'str',
'sp_metadata_url': 'str',

Returns:
'metadata': 'dict'
Expand All @@ -42,7 +43,10 @@ def authorize(self, params: dict) -> dict:
"""
credentials = params["credentials"]
metadata_url = params["options"].get("metadata_url")
sp_metadata_url = params["options"].get("sp_metadata_url")
domain_id = params["domain_id"]
user_info = self.saml_connector.authorize(credentials, metadata_url, domain_id)
user_info = self.saml_connector.authorize(
credentials, metadata_url, sp_metadata_url, domain_id
)

return user_info
Loading