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

An error occurred while retrieving auth cookies #909

Open
hanumavivekm opened this issue Oct 25, 2024 · 0 comments
Open

An error occurred while retrieving auth cookies #909

hanumavivekm opened this issue Oct 25, 2024 · 0 comments
Labels

Comments

@hanumavivekm
Copy link

We have an application that will connecting with sharepoint website and check if a certain file is available. For this we are using Office365-REST-Python-Client==2.4.0 package. Now this works most of the times but fails to connect to SharePoint sometimes. We receive this error in the logs. I would like to understand what the reason behind this failure. The stacktrace bils down to the following file and function.

\Python311\Lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py

def _get_authentication_cookie(self, security_token, federated=False):
        """Retrieve auth cookie from STS

        :type federated: bool
        :type security_token: str
        """
        logger = self.logger(self._get_authentication_cookie.__name__)

        session = requests.session()
        logger.debug_secrets("session: %s\nsession.post(%s, data=%s)", session, self._sts_profile.signin_page_url,
                             security_token)
        if not federated or self._browser_mode:
            headers = {'Content-Type': 'application/x-www-form-urlencoded'}
            if self._browser_mode:
                headers['User-Agent'] = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'
            session.post(self._sts_profile.signin_page_url, data=security_token, headers=headers)
        else:
            idcrl_endpoint = "https://{}/_vti_bin/idcrl.svc/".format(self._sts_profile.tenant)
            session.get(idcrl_endpoint,
                        headers={
                            'User-Agent': 'Office365 Python Client',
                            'X-IDCRL_ACCEPTED': 't',
                            'Authorization': 'BPOSIDCRL {0}'.format(security_token)
                        })
        logger.debug_secrets("session.cookies: %s", session.cookies)
        cookies = requests.utils.dict_from_cookiejar(session.cookies)
        logger.debug_secrets("cookies: %s", cookies)
        if not is_valid_auth_cookies(cookies):
            self.error = "An error occurred while retrieving auth cookies from {0}".format(
                self._sts_profile.signin_page_url)
            logger.error(self.error)
            raise ValueError(self.error)
        return cookies
@vgrem vgrem added the question label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants