class TenantRelationship
A class representing tenant relationships in Azure AD, providing methods to query and validate tenant information across different Azure AD tenants.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/directory/tenant_relationship.py
7 - 23
moderate
Purpose
This class serves as an entity wrapper for managing Azure AD tenant relationships. It enables cross-tenant access configuration by allowing users to search for tenant information using domain names. The primary use case is validating tenant information and retrieving tenant IDs needed for configuring cross-tenant access settings between different Azure AD tenants.
Source Code
class TenantRelationship(Entity):
"""Represent the various type of tenant relationships."""
def find_tenant_information_by_domain_name(self, domain_name):
"""Given a domain name, search for a tenant and read its tenantInformation. You can use this API to
validate tenant information and use their tenantId to configure cross-tenant access settings between you
and the tenant.
:param str domain_name: Primary domain name of an Azure AD tenant.
"""
return_type = ClientResult(self.context, TenantInformation())
params = {"domainName": domain_name}
qry = FunctionQuery(
self, "findTenantInformationByDomainName", params, return_type
)
self.context.add_query(qry)
return return_type
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Entity | - |
Parameter Details
Entity_base_class: Inherits from Entity base class which provides core functionality for interacting with Microsoft Graph API entities. The Entity base class typically provides context management and query execution capabilities.
Return Value
Instantiation returns a TenantRelationship object that inherits Entity capabilities. The find_tenant_information_by_domain_name method returns a ClientResult object containing TenantInformation, which includes details about the queried tenant such as tenant ID and other metadata needed for cross-tenant configuration.
Class Interface
Methods
find_tenant_information_by_domain_name(self, domain_name: str) -> ClientResult
Purpose: Searches for an Azure AD tenant by its primary domain name and retrieves its tenant information, which can be used to validate tenant details and configure cross-tenant access settings
Parameters:
domain_name: The primary domain name of an Azure AD tenant (e.g., 'contoso.com'). This should be a valid, fully-qualified domain name associated with an Azure AD tenant.
Returns: A ClientResult object wrapping a TenantInformation instance. The actual tenant data is populated after context.execute_query() is called. The TenantInformation object contains tenant metadata including tenant ID, domain names, and other tenant-specific details.
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
context |
ClientContext | Inherited from Entity base class. Manages the connection context, authentication, and query execution for Microsoft Graph API calls. Used to queue and execute queries against the API. | instance |
Dependencies
office365
Required Imports
from office365.directory.tenant_information import TenantInformation
from office365.entity import Entity
from office365.runtime.client_result import ClientResult
from office365.runtime.queries.function import FunctionQuery
Usage Example
# Assuming you have a configured context object
from office365.directory.tenant_relationship import TenantRelationship
# Instantiate the TenantRelationship object with a context
# context would be a pre-configured ClientContext or similar
tenant_relationship = TenantRelationship(context)
# Query tenant information by domain name
domain_name = "contoso.com"
result = tenant_relationship.find_tenant_information_by_domain_name(domain_name)
# Execute the query (context-dependent)
context.execute_query()
# Access the tenant information
tenant_info = result.value
print(f"Tenant ID: {tenant_info.tenant_id}")
print(f"Domain Name: {tenant_info.domain_name}")
Best Practices
- Always ensure the context object is properly authenticated before instantiating TenantRelationship
- Call context.execute_query() after invoking find_tenant_information_by_domain_name to actually execute the API request
- The method returns a ClientResult object immediately but the actual data is populated only after execute_query() is called
- Handle cases where the domain name might not exist or the tenant information is not accessible due to permissions
- Use the retrieved tenant ID for configuring cross-tenant access policies
- Validate domain names before passing them to the method to avoid unnecessary API calls
- The class follows a deferred execution pattern - queries are queued and executed in batch when execute_query() is called on the context
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class TenantInformation 68.9% similar
-
class Agreement 65.2% similar
-
class CrossTenantAccessPolicy 61.0% similar
-
class Authentication_v1 60.3% similar
-
class Domain 59.2% similar