Unable to connect to shared enterprise mailbox with python

TiagoFerreira123 0 Reputation points
2025-03-11T15:29:03.86+00:00

I'm trying to read and write in a shared mailbox using python code.

I'm getting this error after running the code, it opens a page with the error:

AADSTS65002: Consent between first party application xxx and first party resource xxx must be configured via preauthorization - applications owned and operated by Microsoft must get approval from the API owner before requesting tokens for that API.

This is the code that I am trying to run:

from msal import PublicClientApplication

CLIENT_ID = "d3xxxx1c"  # Microsoft default public client ID

TENANT_ID = "e0xxxxeb"

SCOPES = ["User.Read"]

app = PublicClientApplication(CLIENT_ID, authority=f"https://login.microsoftonline.com/{TENANT_ID}")

token_result = app.acquire_token_interactive(SCOPES)

print(token_result)  # This should return an access token

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
4,313 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.