Пример #1
0
    async def link_user_to_identity_provider(
            self,
            idpId,
            userId,
            user_identity_provider_link_request,
            keep_empty_params=False):
        """
        Links an Okta user to an existing Social Identity Provi
        der. This does not support the SAML2 Identity Provider
        Type
        Args:
            idp_id {str}
            user_id {str}
            {user_identity_provider_link_request}
        Returns:
            IdentityProviderApplicationUser
        """
        http_method = "post".upper()
        api_url = format_url(f"""
            {self._base_url}
            /api/v1/idps/{idpId}/users/{userId}
            """)

        if isinstance(user_identity_provider_link_request, dict):
            body = user_identity_provider_link_request
        else:
            body = user_identity_provider_link_request.as_dict()
        headers = {
            "Accept": "application/json",
            "Content-Type": "application/json"
        }
        form = {}

        request, error = await self._request_executor.create_request(
            http_method,
            api_url,
            body,
            headers,
            form,
            keep_empty_params=keep_empty_params)

        if error:
            return (None, None, error)

        response, error = await self._request_executor\
            .execute(request, IdentityProviderApplicationUser)

        if error:
            return (None, response, error)

        try:
            result = IdentityProviderApplicationUser(
                self.form_response_body(response.get_body()))
        except Exception as error:
            return (None, response, error)
        return (result, response, None)
Пример #2
0
    async def list_identity_provider_application_users(self,
                                                       idpId,
                                                       keep_empty_params=False
                                                       ):
        """
        Find all the users linked to an identity provider
        Args:
            idp_id {str}
        Returns:
            list: Collection of IdentityProviderApplicationUser instances.
        """
        http_method = "get".upper()
        api_url = format_url(f"""
            {self._base_url}
            /api/v1/idps/{idpId}/users
            """)

        body = {}
        headers = {}
        form = {}

        request, error = await self._request_executor.create_request(
            http_method,
            api_url,
            body,
            headers,
            form,
            keep_empty_params=keep_empty_params)

        if error:
            return (None, None, error)

        response, error = await self._request_executor\
            .execute(request, IdentityProviderApplicationUser)

        if error:
            return (None, response, error)

        try:
            result = []
            for item in response.get_body():
                result.append(
                    IdentityProviderApplicationUser(
                        self.form_response_body(item)))
        except Exception as error:
            return (None, response, error)
        return (result, response, None)
Пример #3
0
    async def get_identity_provider_application_user(self,
                                                     idpId,
                                                     userId,
                                                     keep_empty_params=False):
        """
        Fetches a linked IdP user by ID
        Args:
            idp_id {str}
            user_id {str}
        Returns:
            IdentityProviderApplicationUser
        """
        http_method = "get".upper()
        api_url = format_url(f"""
            {self._base_url}
            /api/v1/idps/{idpId}/users/{userId}
            """)

        body = {}
        headers = {}
        form = {}

        request, error = await self._request_executor.create_request(
            http_method,
            api_url,
            body,
            headers,
            form,
            keep_empty_params=keep_empty_params)

        if error:
            return (None, None, error)

        response, error = await self._request_executor\
            .execute(request, IdentityProviderApplicationUser)

        if error:
            return (None, response, error)

        try:
            result = IdentityProviderApplicationUser(
                self.form_response_body(response.get_body()))
        except Exception as error:
            return (None, response, error)
        return (result, response, None)