Krishna Namani
Krishna Namani

Reputation: 1

Access to two factor authentication sharepoint wesite with python

I am trying to download a file from sharepoint using python(for automation purposes). Sharepoint has two factor authetication(VIP access). I tried using Office365-REST-Python-Client library to log in with username and password, but unable to log in. The page is redirected to VIP access page which asks for OTP when accessed manually through web page. How to read the second step of the access(VIP access) in python and input the code that is sent to my local.

I tried Office365-REST-Python-Client library to log in with username and password, but didn't get very far from there.

Upvotes: 0

Views: 325

Answers (1)

RaytheonXie-MSFT
RaytheonXie-MSFT

Reputation: 1

To access a SharePoint website with two-factor authentication (2FA) using Python, you'll need to use an authentication method that supports 2FA, such as the Microsoft Azure Active Directory (AAD) authentication flow.You can refer to following code

site_url = "https://your-sharepoint-site-url"
client_id = "your-azure-ad-app-client-id"
client_secret = "your-azure-ad-app-client-secret"
app = PublicClientApplication(client_id)
result = app.acquire_token_interactive(scopes=["https://graph.microsoft.com/.default"])
access_token = result["access_token"]

Upvotes: 0

Related Questions