Error Encountered: OrganizationFromTenantGuidNotFound

Elman Safarli 0 Баллы репутации
2024-09-17T00:25:21.8933333+00:00

We are encountering an error related to Microsoft Graph API integration in our Django application. Specifically, the error message is:


{
    "error": {
        "

This happens when trying to authenticate using Azure AD and fetch emails via Microsoft Graph API. The decoded token shows a valid tenant_id, client_id, and permissions, but we suspect there might be an issue with the tenant configuration or app registration on Azure.

At the moment, using the token, I can get a list of all users. However, when I go to the information on a specific user, an error occurs. However, on the application side, no errors are displayed. My main task is to configure the functionality of sending messages from my application, so that messages sent to the user's address are visible in the application (also when sending a message to a user).

https://graph.microsoft.com/v1.0/users/

{
    

https://graph.microsoft.com/v1.0/users/[email protected]

{ "error": { "code": "Request_ResourceNotFound", "message": "Resource '[email protected]' does not exist or one of its queried reference-property objects are not present.", "innerError": { "date": "2024-09-16T18:52:55", "request-id": "0a7e7545-598b-42d6-8d0f-afbac98f26d0", "client-request-id": "0a7e7545-598b-42d6-8d0f-afbac98f26d0" } } }

We've ensured that:

The tenant ID is correctly set in our Django settings. The app is registered in Azure AD with the correct permissions, including Mail.Read and Mail.ReadWrite. Admin consent has been granted for all required permissions.

from msal import ConfidentialClientApplication
from django.conf import settings
import requests
import json

client_id = settings.AZURE_CLIENT_ID
client_secret = settings.AZURE_CLIENT_SECRET
tenant_id = settings.AZURE_TENANT_ID

msal_authority = f"https://login.microsoftonline.com/{tenant_id}"

def get_microsoft_graph_access_token():
    url = f"https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token"
    payload = {
        "grant_type": "client_credentials",
        "client_id": client_id,
        "client_secret": client_secret,
        "scope": "https://graph.microsoft.com/.default",
    }

    response = requests.post(url, data=payload)
    responce_data = response.json()
    access_token = responce_data["access_token"]
    print(access_token)
    return access_token


def read_email():
    access_token = get_microsoft_graph_access_token()
    headers = {
        "Authorization": f"Bearer {access_token}",
        "Content-Type": "application/json",
    }

    url = "https://graph.microsoft.com/v1.0/users/user_mail/messages"
    response = requests.get(url, headers=headers)

    
    if response.status_code == 200:
        graph_data = response.json()
        print(json.dumps(graph_data, indent=2))
    else:
        error_data = response.json()  
        print(json.dumps(error_data, indent=2))
Azure
Azure
Платформа и инфраструктура облачных вычислений для создания, развертывания приложений и служб и управления ими через глобальную сеть центров обработки данных, управляемых корпорацией Майкрософт.
Вопросы: 54
Голосов: {count}

1 ответ

Сортировать по: Наиболее полезные
  1. Ivan Prodanov (Convergys Corporation) 0 Баллы репутации Поставщик Майкрософт
    2024-09-17T13:54:15.46+00:00

    Hello,

    This is a Russian speaking Q&A. Would you like to continue working on your issue in Russian? In case you wish to continue in English, you may ask your question on the English Q&A


Ваш ответ

Автор вопроса может помечать ответы как принятые. Это позволяет пользователям узнать, что ответ помог решить проблему автора.