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 from https://mycompany.sharepoint.com/sites/documentssite//_vti_bin/idcrl.svc #247

Closed
NathanSalez opened this issue Aug 5, 2020 · 3 comments
Labels

Comments

@NathanSalez
Copy link

NathanSalez commented Aug 5, 2020

Hello there,

Context of the issue

I'm working with the version 2.1.7.post1 (according to pip freeze), no MFA required to log in sharepoint.
I'm currently trying to get an excel file from the company's sharepoint, with the following script (built from README of the project) :

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.file import File

url = 'https://mycompany.sharepoint.com/sites/documentssite/'

ctx_auth = AuthenticationContext(url)
if ctx_auth.acquire_token_for_user(username, password):
    ctx = ClientContext(url, ctx_auth)
    web = ctx.web
    ctx.load(web)
    ctx.execute_query()
    print("Web title: {0}".format(web.properties['Title']))

Running this script provides the following output :
An error occurred while retrieving auth cookies from https://mycompany.sharepoint.com/sites/documentssite//_vti_bin/idcrl.svc

Some details about the issue

I noticed by running this script in debug mode, that the issue comes from the method acquire_authentication_cookie of the class SamlTokenProvider
Actually, the method is called with federated=True so the HTTP request is done at https://mycompany.sharepoint.com/sites/documentssite//_vti_bin/idcrl.svc with the HEAD method. You can find below the part where it fails :

     def acquire_authentication_cookie(self, security_token, federated=False):
        ...
        else:
            self._auth_cookies['SPOIDCRL'] = None
            session.head(self.__sts_profile.signInPageUrl,
                         headers={
                             'User-Agent': 'Office365 Python Client',
                             'X-IDCRL_ACCEPTED': 't',
                             'Authorization': 'BPOSIDCRL {0}'.format(security_token),
                             'Content-Type': 'application/x-www-form-urlencoded'
                         })
        logger.debug_secrets("session.cookies: %s", session.cookies)
        cookies = requests.utils.dict_from_cookiejar(session.cookies)
        logger.debug_secrets("cookies: %s", cookies)
        if not cookies:
            self.error = "An error occurred while retrieving auth cookies from {0}".format(self.__sts_profile.signInPageUrl)
            logger.error(self.error)
            return False

The response does not contain any cookie, that's why I get the message error.

By the way, I got the same problem when I set url to 'https://mycompany.sharepoint.com'.

Let me know if I haven't given enough details about the issue.
Thank you in advance !

@NathanSalez
Copy link
Author

Some news about the issue :

When I make a HEAD request to https://mycompany.sharepoint.com/sites/documentssite//_vti_bin/idcrl.svc with curl, I got redirected to https://mycompany.sharepoint.com/_vti_bin/idcrl.svc/ (response code : 307).

So I made a HEAD request to this link, I got a Method Not Allowed response...
I guess the issue comes from my company's side..

@vgrem vgrem added the question label Aug 6, 2020
@vgrem
Copy link
Owner

vgrem commented Aug 6, 2020

Greetings!

Thank you for the provided details!

2.1.7.post1 is a bit outdated at the moment, could you please give it another shot but with the latest version (2.1.10.1 at the moment), it could be downloaded via GitHub:

pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git

or from an alternative index

A few bug fixes have been resolved since then in terms of authentication.

@NathanSalez
Copy link
Author

I installed the last version and it works fine ! (That was quite simple to solve it actually ! :) )
Thank you for the help :D

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