Beispiel #1
0
    def get_assertion(self, appid):
        """Call Okta and get the assertion.

        Args: String appid

        Returns: String SAML response
        """
        path = "{url}/home/amazon_aws/{appid}".format(
            url=self.base_url,
            appid=appid,
        )
        headers = {
            "Accept": "application/json",
            "User-Agent": f"aws_okta_keyman/{__version__}",
            "Content-Type": "application/json",
        }
        resp = self.session.get(
            path,
            cookies={"sid": self.session_token},
            headers=headers,
        )

        if "second-factor" in resp.url:
            try:
                state_token = self.get_state_token_from_html(resp.text)
                LOG.debug("Redirected; reuathing with new token")
                raise okta.ReauthNeeded(state_token)
            except AttributeError:
                LOG.debug("Error finding state token in response")
                raise okta.ReauthNeeded()

        try:
            resp.raise_for_status()
        except (
                requests.exceptions.HTTPError,
                requests.exceptions.ConnectionError,
        ) as err:
            if err.response.status_code == 404:
                LOG.fatal(f"Provided App ID {appid} not found")
                LOG.fatal("404 calling ")
            else:
                LOG.error(
                    "Unknown error: {msg}".format(msg=str(
                        err.response.__dict__), ), )
            raise okta.UnknownError()

        assertion = self.assertion(resp.text)
        if assertion == b"":
            error = self.get_okta_error_from_response(resp)
            LOG.fatal(error)
            raise okta.UnknownError()
        return assertion
Beispiel #2
0
    def test_class_properties(self):
        error_response = None
        try:
            raise okta.ReauthNeeded('state_token')
        except okta.ReauthNeeded as err:
            error_response = err

        self.assertEqual(error_response.state_token, 'state_token')
Beispiel #3
0
    def get_assertion(self, appid):
        """Call Okta and get the assertion.

        Args: String appid

        Returns: String SAML response
        """
        path = '{url}/home/amazon_aws/{appid}'.format(url=self.base_url,
                                                      appid=appid)
        resp = self.session.get(path, cookies={'sid': self.session_token})

        if 'second-factor' in resp.url:
            try:
                state_token = self.get_state_token_from_html(resp.text)
                LOG.debug("Redirected; reuathing with new token")
                raise okta.ReauthNeeded(state_token)
            except AttributeError:
                LOG.debug("Error finding state token in response")
                raise okta.ReauthNeeded()

        try:
            resp.raise_for_status()
        except (requests.exceptions.HTTPError,
                requests.exceptions.ConnectionError) as err:
            if err.response.status_code == 404:
                LOG.fatal("Provided App ID {} not found".format(appid))
            else:
                LOG.error('Unknown error: {msg}'.format(
                    msg=str(err.response.__dict__)))
            raise okta.UnknownError()

        assertion = self.assertion(resp.text)
        if assertion == b'':
            err = self.get_okta_error_from_response(resp)
            LOG.fatal(err)
            raise okta.UnknownError()
        return assertion