Upravit

Sdílet prostřednictvím


Access national cloud deployments with the Microsoft Graph SDKs

By default, the Microsoft Graph SDKs are configured to access data in the Microsoft Graph global service, using the https://graph.microsoft.com root URL to access the Microsoft Graph REST API. Developers can override this configuration to connect to Microsoft Graph national cloud deployments.

Prerequisites

You will need the following information to configure a Microsoft Graph SDK to connect to a national cloud deployment.

Configure the SDK

In order to connect to a national cloud deployment, you must configure your authentication provider to connect to the correct token service endpoint. Then you must configure the SDK client to connect to the correct Microsoft Graph service root endpoint.

Permission scopes

Any permission scope value (including the .default scope) that contains the Microsoft Graph domain MUST use the domain of the Microsoft Graph service root endpoint for the national cloud deployment. The shortened permission scope names, such as User.Read or Mail.Send, are also valid.

Examples

The following example configures an Interactive authentication provider with the Microsoft Graph SDK to connect to the Microsoft Graph for US Government L4 national cloud.

// Create the InteractiveBrowserCredential using details
// from app registered in the Azure AD for US Government portal
var credential = new InteractiveBrowserCredential(
    "YOUR_TENANT_ID",
    "YOUR_CLIENT_ID",
    new InteractiveBrowserCredentialOptions
    {
        // https://login.microsoftonline.us
        AuthorityHost = AzureAuthorityHosts.AzureGovernment,
        RedirectUri = new Uri("YOUR_REDIRECT_URI"),
    });

// Create the authentication provider
var authProvider = new AzureIdentityAuthenticationProvider(
    credential,
    isCaeEnabled: true,
    scopes: ["https://graph.microsoft.us/.default"]);

// Create the Microsoft Graph client object using
// the Microsoft Graph for US Government L4 endpoint
// NOTE: The API version must be included in the URL
var graphClient = new GraphServiceClient(
    authProvider,
    "https://graph.microsoft.us/v1.0");